Merge pull request #150 from SyncrowIOT/SP-1440-FE-On-routine-creation-edit-Page-When-saving-a-routine-the-confirmation-pop-up-is-not-identical-to-design

Sp 1440 fe on routine creation edit page when saving a routine the confirmation pop up is not identical to design
This commit is contained in:
Faris Armoush
2025-04-21 18:59:37 +03:00
committed by GitHub
4 changed files with 235 additions and 136 deletions

View File

@ -55,12 +55,12 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
final isSmallScreen = isSmallScreenSize(context); final isSmallScreen = isSmallScreenSize(context);
final isMediumScreen = isMediumScreenSize(context); final isMediumScreen = isMediumScreenSize(context);
Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;
late ScrollController _scrollController; late ScrollController scrollController;
_scrollController = ScrollController(); scrollController = ScrollController();
void _scrollToCenter() { void scrollToCenter() {
final double middlePosition = _scrollController.position.maxScrollExtent / 2; final double middlePosition = scrollController.position.maxScrollExtent / 2;
_scrollController.animateTo( scrollController.animateTo(
middlePosition, middlePosition,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
curve: Curves.easeInOut, curve: Curves.easeInOut,
@ -68,7 +68,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
} }
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToCenter(); scrollToCenter();
}); });
return Stack( return Stack(
@ -76,7 +76,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
FirstLayer( FirstLayer(
second: Center( second: Center(
child: ListView( child: ListView(
controller: _scrollController, controller: scrollController,
shrinkWrap: true, shrinkWrap: true,
children: [ children: [
Container( Container(
@ -199,7 +199,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
width: size.width * 0.9, width: size.width * 0.9,
child: DropdownButtonHideUnderline( child: DropdownButtonHideUnderline(
child: DropdownButton2<String>( child: DropdownButton2<String>(
style: TextStyle(color: Colors.black), style: const TextStyle(color: Colors.black),
isExpanded: true, isExpanded: true,
hint: Text( hint: Text(
'Select your region/country', 'Select your region/country',
@ -336,6 +336,16 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
obscureText: loginBloc.obscureText, obscureText: loginBloc.obscureText,
keyboardType: TextInputType.visiblePassword, keyboardType: TextInputType.visiblePassword,
controller: loginBloc.loginPasswordController, controller: loginBloc.loginPasswordController,
onFieldSubmitted: (value) {
if (loginBloc.loginFormKey.currentState!.validate()) {
loginBloc.add(LoginButtonPressed(
username: loginBloc.loginEmailController.text,
password: value,
));
} else {
loginBloc.add(ChangeValidateEvent());
}
},
decoration: textBoxDecoration()!.copyWith( decoration: textBoxDecoration()!.copyWith(
hintText: 'At least 8 characters', hintText: 'At least 8 characters',
hintStyle: Theme.of(context) hintStyle: Theme.of(context)
@ -393,7 +403,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
Transform.scale( Transform.scale(
scale: 1.2, scale: 1.2,
child: Checkbox( child: Checkbox(
fillColor: MaterialStateProperty.all<Color>(Colors.white), fillColor: WidgetStateProperty.all<Color>(Colors.white),
activeColor: Colors.white, activeColor: Colors.white,
value: loginBloc.isChecked, value: loginBloc.isChecked,
checkColor: Colors.black, checkColor: Colors.black,

View File

@ -5,7 +5,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
import 'package:syncrow_web/pages/routines/models/device_functions.dart'; import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/constants/assets.dart';
@ -15,13 +14,18 @@ class SaveRoutineHelper {
static Future<void> showSaveRoutineDialog(BuildContext context) async { static Future<void> showSaveRoutineDialog(BuildContext context) async {
return showDialog<void>( return showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (context) {
return BlocBuilder<RoutineBloc, RoutineState>( return BlocBuilder<RoutineBloc, RoutineState>(
builder: (context, state) { builder: (context, state) {
final selectedConditionLabel = state.selectedAutomationOperator == 'and'
? 'All Conditions are met'
: 'Any Condition is met';
return AlertDialog( return AlertDialog(
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
content: Container( content: Container(
width: MediaQuery.sizeOf(context).width * 0.5, width: context.screenWidth * 0.5,
height: 500,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
@ -29,99 +33,42 @@ class SaveRoutineHelper {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
DialogHeader('Create a scene: ${state.routineName ?? ""}'), const SizedBox(height: 18),
Padding( Text(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), 'Create a scene: ${state.routineName ?? ""}',
child: Row( textAlign: TextAlign.center,
crossAxisAlignment: CrossAxisAlignment.start, style: Theme.of(context).textTheme.headlineMedium!.copyWith(
children: [ color: ColorsManager.primaryColorWithOpacity,
// Left side - IF fontWeight: FontWeight.bold,
Expanded(
child: ListView(
// crossAxisAlignment: CrossAxisAlignment.start,
shrinkWrap: true,
children: [
const Text(
'IF:',
style: TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 8),
if (state.isTabToRun)
ListTile(
leading: SvgPicture.asset(
Assets.tabToRun,
width: 24,
height: 24,
),
title: const Text('Tab to run'),
),
if (state.isAutomation)
...state.ifItems.map((item) {
final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}),
],
),
), ),
const SizedBox(width: 16), ),
// Right side - THEN items const SizedBox(height: 18),
_buildDivider(),
Expanded( _buildListsLabelRow(selectedConditionLabel),
child: ListView( Expanded(
// crossAxisAlignment: CrossAxisAlignment.start, child: Padding(
shrinkWrap: true, padding: const EdgeInsetsDirectional.symmetric(
children: [ horizontal: 16,
const Text( ),
'THEN:', child: Row(
style: TextStyle( crossAxisAlignment: CrossAxisAlignment.start,
fontSize: 16, mainAxisSize: MainAxisSize.min,
), spacing: 24,
), children: [
const SizedBox(height: 8), _buildIfConditions(state, context),
...state.thenItems.map((item) { Container(
final functions = width: 1,
state.selectedFunctions[item['uniqueCustomId']] ?? []; color: ColorsManager.greyColor.withValues(alpha: 0.8),
return functionRow(item, context, functions);
}),
],
), ),
), _buildThenActions(state, context),
], ],
),
), ),
), ),
// if (state.errorMessage != null || state.errorMessage!.isNotEmpty) _buildDivider(),
// Padding( const SizedBox(height: 8),
// padding: const EdgeInsets.all(8.0), _buildDialogFooter(context, state),
// child: Text( const SizedBox(height: 8),
// state.errorMessage!,
// style: const TextStyle(color: Colors.red),
// ),
// ),
DialogFooter(
onCancel: () => Navigator.pop(context),
onConfirm: () async {
if (state.isAutomation) {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateAutomation());
} else {
context.read<RoutineBloc>().add(const CreateAutomationEvent());
}
} else {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateScene());
} else {
context.read<RoutineBloc>().add(const CreateSceneEvent());
}
}
// if (state.errorMessage == null || state.errorMessage!.isEmpty) {
Navigator.pop(context);
// }
},
isConfirmEnabled: true,
),
], ],
), ),
), ),
@ -132,8 +79,107 @@ class SaveRoutineHelper {
); );
} }
static Container _buildDivider() {
return Container(
height: 1,
width: double.infinity,
color: ColorsManager.greyColor,
);
}
static Widget _buildListsLabelRow(String selectedConditionLabel) {
const textStyle = TextStyle(
fontSize: 16,
);
return Container(
color: ColorsManager.backgroundColor.withValues(alpha: 0.5),
padding: const EdgeInsetsDirectional.all(20),
child: Row(
spacing: 16,
children: [
Expanded(child: Text('IF: $selectedConditionLabel', style: textStyle)),
const Expanded(child: Text('THEN:', style: textStyle)),
],
),
);
}
static Widget _buildDialogFooter(BuildContext context, RoutineState state) {
return Row(
spacing: 16,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
DialogFooterButton(
text: 'Cancel',
onTap: () => Navigator.pop(context),
),
DialogFooterButton(
text: 'Confirm',
onTap: () {
if (state.isAutomation) {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateAutomation());
} else {
context.read<RoutineBloc>().add(const CreateAutomationEvent());
}
} else {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateScene());
} else {
context.read<RoutineBloc>().add(const CreateSceneEvent());
}
}
Navigator.pop(context);
},
textColor: ColorsManager.primaryColorWithOpacity,
),
],
);
}
static Widget _buildThenActions(RoutineState state, BuildContext context) {
return Expanded(
child: ListView(
// shrinkWrap: true,
children: state.thenItems.map((item) {
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}).toList(),
),
);
}
static Widget _buildIfConditions(RoutineState state, BuildContext context) {
return Expanded(
child: ListView(
// shrinkWrap: true,
children: [
if (state.isTabToRun)
ListTile(
leading: SvgPicture.asset(
Assets.tabToRun,
width: 24,
height: 24,
),
title: const Text('Tab to run'),
),
if (state.isAutomation)
...state.ifItems.map((item) {
final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}),
],
),
);
}
static Widget functionRow( static Widget functionRow(
dynamic item, BuildContext context, List<DeviceFunctionData> functions) { dynamic item,
BuildContext context,
List<DeviceFunctionData> functions,
) {
return Padding( return Padding(
padding: const EdgeInsets.only(top: 6), padding: const EdgeInsets.only(top: 6),
child: Row( child: Row(
@ -142,19 +188,36 @@ class SaveRoutineHelper {
Expanded( Expanded(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
spacing: 8, spacing: 17,
children: [ children: [
item['type'] == 'tap_to_run' || item['type'] == 'scene' Container(
? Image.memory( width: 22,
base64Decode(item['icon']), height: 22,
width: 22, padding: const EdgeInsetsDirectional.all(4),
height: 22, decoration: BoxDecoration(
) shape: BoxShape.circle,
: SvgPicture.asset( color: ColorsManager.textFieldGreyColor,
item['imagePath'], border: Border.all(
width: 22, color: ColorsManager.neutralGray,
height: 22, width: 1.5,
), ),
),
child: Center(
child: item['type'] == 'tap_to_run' || item['type'] == 'scene'
? Image.memory(
base64Decode(item['icon']),
width: 12,
height: 22,
fit: BoxFit.scaleDown,
)
: SvgPicture.asset(
item['imagePath'],
width: 12,
height: 12,
fit: BoxFit.scaleDown,
),
),
),
Flexible( Flexible(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -166,19 +229,25 @@ class SaveRoutineHelper {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
fontSize: 14, fontSize: 15,
color: ColorsManager.textPrimaryColor, color: ColorsManager.textPrimaryColor,
), ),
), ),
Wrap( Wrap(
runSpacing: 16,
spacing: 4,
children: functions children: functions
.map((f) => Text( .map(
'${f.operationName}: ${f.value}', (function) => Text(
style: context.textTheme.bodySmall '${function.operationName}: ${function.value}',
?.copyWith(color: ColorsManager.grayColor, fontSize: 8), style: context.textTheme.bodySmall?.copyWith(
overflow: TextOverflow.ellipsis, color: ColorsManager.grayColor,
maxLines: 3, fontSize: 8,
)) ),
overflow: TextOverflow.ellipsis,
maxLines: 3,
),
)
.toList(), .toList(),
), ),
], ],
@ -197,7 +266,13 @@ class SaveRoutineHelper {
child: Row( child: Row(
spacing: 2, spacing: 2,
children: [ children: [
SizedBox(width: 8, height: 8, child: SvgPicture.asset(Assets.deviceTagIcon)), SizedBox(
width: 8,
height: 8,
child: SvgPicture.asset(
Assets.deviceTagIcon,
),
),
Text( Text(
item['tag'] ?? '', item['tag'] ?? '',
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -218,7 +293,12 @@ class SaveRoutineHelper {
spacing: 2, spacing: 2,
children: [ children: [
SizedBox( SizedBox(
width: 8, height: 8, child: SvgPicture.asset(Assets.spaceLocationIcon)), width: 8,
height: 8,
child: SvgPicture.asset(
Assets.spaceLocationIcon,
),
),
Text( Text(
item['subSpace'] ?? '', item['subSpace'] ?? '',
textAlign: TextAlign.center, textAlign: TextAlign.center,

View File

@ -28,32 +28,40 @@ class DialogFooter extends StatelessWidget {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildFooterButton( DialogFooterButton(
context: context,
text: 'Cancel', text: 'Cancel',
onTap: onCancel, onTap: onCancel,
), ),
if (isConfirmEnabled) ...[ if (isConfirmEnabled) ...[
Container(width: 1, height: 50, color: ColorsManager.greyColor), Container(width: 1, height: 50, color: ColorsManager.greyColor),
_buildFooterButton( DialogFooterButton(
context: context,
text: 'Confirm', text: 'Confirm',
onTap: onConfirm, onTap: onConfirm,
textColor: textColor: isConfirmEnabled
isConfirmEnabled ? ColorsManager.primaryColorWithOpacity : Colors.red, ? ColorsManager.primaryColorWithOpacity
: Colors.red,
), ),
], ],
], ],
), ),
); );
} }
}
Widget _buildFooterButton({ class DialogFooterButton extends StatelessWidget {
required BuildContext context, const DialogFooterButton({
required String text, required this.text,
required VoidCallback? onTap, required this.onTap,
Color? textColor, this.textColor,
}) { super.key,
});
final String text;
final VoidCallback? onTap;
final Color? textColor;
@override
Widget build(BuildContext context) {
return Expanded( return Expanded(
child: TextButton( child: TextButton(
style: TextButton.styleFrom( style: TextButton.styleFrom(

View File

@ -16,6 +16,7 @@ class DialogHeader extends StatelessWidget {
), ),
Text( Text(
title, title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium!.copyWith( style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: ColorsManager.primaryColorWithOpacity, color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,