update scene debug

This commit is contained in:
ashrafzarkanisala
2024-12-01 00:42:00 +03:00
parent b732b0b957
commit 938f8c6b51
12 changed files with 504 additions and 301 deletions

View File

@ -10,14 +10,41 @@ import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/style.dart';
class RoutineSearchAndButtons extends StatelessWidget {
class RoutineSearchAndButtons extends StatefulWidget {
const RoutineSearchAndButtons({
super.key,
});
@override
State<RoutineSearchAndButtons> createState() =>
_RoutineSearchAndButtonsState();
}
class _RoutineSearchAndButtonsState extends State<RoutineSearchAndButtons> {
late TextEditingController _nameController;
@override
void initState() {
super.initState();
_nameController = TextEditingController();
}
@override
void dispose() {
_nameController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<RoutineBloc, RoutineState>(
return BlocConsumer<RoutineBloc, RoutineState>(
listenWhen: (previous, current) =>
previous.routineName != current.routineName,
listener: (context, state) {
if (state.routineName != _nameController.text) {
_nameController.text = state.routineName ?? '';
}
},
builder: (context, state) {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
@ -35,26 +62,9 @@ class RoutineSearchAndButtons extends StatelessWidget {
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxWidth:
constraints.maxWidth > 700 ? 450 : constraints.maxWidth - 32),
// child: StatefulTextField(
// title: 'Routine Name',
// initialValue: state.routineName ?? '',
// height: 40,
// // controller: TextEditingController(),
// hintText: 'Please enter the name',
// boxDecoration: containerWhiteDecoration,
// elevation: 0,
// borderRadius: 15,
// isRequired: true,
// width: 450,
// onSubmitted: (value) {
// // context.read<RoutineBloc>().add(SetRoutineName(value));
// },
// onChanged: (value) {
// context.read<RoutineBloc>().add(SetRoutineName(value));
// },
// ),
maxWidth: constraints.maxWidth > 700
? 450
: constraints.maxWidth - 32),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
@ -63,10 +73,13 @@ class RoutineSearchAndButtons extends StatelessWidget {
children: [
Text('* ',
style: context.textTheme.bodyMedium!
.copyWith(color: ColorsManager.red, fontSize: 13)),
.copyWith(
color: ColorsManager.red,
fontSize: 13)),
Text(
'Routine Name',
style: context.textTheme.bodyMedium!.copyWith(
style: context.textTheme.bodyMedium!
.copyWith(
fontSize: 13,
fontWeight: FontWeight.w600,
color: ColorsManager.blackColor,
@ -80,18 +93,24 @@ class RoutineSearchAndButtons extends StatelessWidget {
decoration: containerWhiteDecoration,
child: TextFormField(
style: context.textTheme.bodyMedium!
.copyWith(color: ColorsManager.blackColor),
initialValue: state.routineName,
.copyWith(
color: ColorsManager.blackColor),
controller: _nameController,
decoration: InputDecoration(
hintText: 'Please enter the name',
hintStyle: context.textTheme.bodyMedium!
.copyWith(fontSize: 12, color: ColorsManager.grayColor),
.copyWith(
fontSize: 12,
color: ColorsManager.grayColor),
contentPadding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
const EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
border: InputBorder.none,
),
onChanged: (value) {
context.read<RoutineBloc>().add(SetRoutineName(value));
context
.read<RoutineBloc>()
.add(SetRoutineName(value));
},
validator: (value) {
if (value == null || value.isEmpty) {
@ -111,15 +130,17 @@ class RoutineSearchAndButtons extends StatelessWidget {
width: 200,
child: Center(
child: DefaultButton(
onPressed: state.isAutomation || state.isTabToRun
onPressed: state.isAutomation ||
state.isTabToRun
? () async {
final result = await SettingHelper.showSettingDialog(
final result = await SettingHelper
.showSettingDialog(
context: context,
iconId: state.selectedIcon,
);
if (result != null) {
context
.read<RoutineBloc>()
.add(AddSelectedIcon(result));
context.read<RoutineBloc>().add(
AddSelectedIcon(result));
}
}
: null,
@ -175,10 +196,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
child: Center(
child: DefaultButton(
onPressed: () async {
if (state.routineName == null || state.routineName!.isEmpty) {
if (state.routineName == null ||
state.routineName!.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Please enter the routine name'),
content: const Text(
'Please enter the routine name'),
duration: const Duration(seconds: 2),
backgroundColor: ColorsManager.red,
action: SnackBarAction(
@ -192,10 +215,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
return;
}
if (state.ifItems.isEmpty || state.thenItems.isEmpty) {
if (state.ifItems.isEmpty ||
state.thenItems.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Please add if and then condition'),
content: const Text(
'Please add if and then condition'),
duration: const Duration(seconds: 2),
backgroundColor: ColorsManager.red,
action: SnackBarAction(
@ -208,13 +233,15 @@ class RoutineSearchAndButtons extends StatelessWidget {
);
return;
}
final result =
await SaveRoutineHelper.showSaveRoutineDialog(context);
final result = await SaveRoutineHelper
.showSaveRoutineDialog(context);
if (result != null && result) {
BlocProvider.of<SwitchTabsBloc>(context).add(
BlocProvider.of<SwitchTabsBloc>(context)
.add(
const CreateNewRoutineViewEvent(false),
);
BlocProvider.of<SwitchTabsBloc>(context).add(
BlocProvider.of<SwitchTabsBloc>(context)
.add(
const TriggerSwitchTabsEvent(true),
);
}
@ -248,11 +275,15 @@ class RoutineSearchAndButtons extends StatelessWidget {
child: DefaultButton(
onPressed: state.isAutomation || state.isTabToRun
? () async {
final result = await SettingHelper.showSettingDialog(
final result =
await SettingHelper.showSettingDialog(
context: context,
iconId: state.selectedIcon,
);
if (result != null) {
context.read<RoutineBloc>().add(AddSelectedIcon(result));
context
.read<RoutineBloc>()
.add(AddSelectedIcon(result));
}
}
: null,
@ -302,10 +333,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
child: Center(
child: DefaultButton(
onPressed: () async {
if (state.routineName == null || state.routineName!.isEmpty) {
if (state.routineName == null ||
state.routineName!.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Please enter the routine name'),
content: const Text(
'Please enter the routine name'),
duration: const Duration(seconds: 2),
backgroundColor: ColorsManager.red,
action: SnackBarAction(
@ -319,10 +352,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
return;
}
if (state.ifItems.isEmpty || state.thenItems.isEmpty) {
if (state.ifItems.isEmpty ||
state.thenItems.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Please add if and then condition'),
content: const Text(
'Please add if and then condition'),
duration: const Duration(seconds: 2),
backgroundColor: ColorsManager.red,
action: SnackBarAction(
@ -335,7 +370,9 @@ class RoutineSearchAndButtons extends StatelessWidget {
);
return;
}
final result = await SaveRoutineHelper.showSaveRoutineDialog(context);
final result =
await SaveRoutineHelper.showSaveRoutineDialog(
context);
if (result != null && result) {
BlocProvider.of<SwitchTabsBloc>(context).add(
const CreateNewRoutineViewEvent(false),