From 8d6d5da5cd366681821e32d14b18e7c3cc9872ae Mon Sep 17 00:00:00 2001 From: mohammad Date: Sat, 29 Jun 2024 00:32:19 +0300 Subject: [PATCH] CreateTemporaryPassword --- .../bloc/smart_door_bloc/smart_door_bloc.dart | 7 +- .../smart_door/create_temporary_password.dart | 144 ++++++++++-------- 2 files changed, 84 insertions(+), 67 deletions(-) diff --git a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart index e14b181..29d8a80 100644 --- a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart +++ b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart @@ -24,10 +24,11 @@ class SmartDoorBloc extends Bloc { List? selectedDay; DateTime? startTime; - DateTime? endTime ; // This sets the date to December 31, 2050. + DateTime? endTime ; changeTime(val,isStartEndTime){ + emit(LoadingInitialState()); if(isStartEndTime==true){ startTime=val; }else{ @@ -37,6 +38,7 @@ class SmartDoorBloc extends Bloc { } bool repeatFunction() { + emit(LoadingInitialState()); repeat = !repeat; emit(IsRepeatState()); return repeat; @@ -195,10 +197,7 @@ class SmartDoorBloc extends Bloc { ); return; } - } -//["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] - List days = [ DayInWeek( "Sun", diff --git a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart index 826b963..93856b2 100644 --- a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart +++ b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart @@ -8,13 +8,18 @@ import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_sta import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; -import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:time_picker_spinner/time_picker_spinner.dart'; -class CreateTemporaryPassword extends StatelessWidget { +class CreateTemporaryPassword extends StatefulWidget { const CreateTemporaryPassword({super.key}); + @override + State createState() => + _CreateTemporaryPasswordState(); +} + +class _CreateTemporaryPasswordState extends State { @override Widget build(BuildContext context) { return BlocProvider( @@ -45,7 +50,8 @@ class CreateTemporaryPassword extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const BodyMedium( - text: 'Save the password immediately. The password is not displayed in the app.', + text: + 'Save the password immediately. The password is not displayed in the app.', fontWeight: FontWeight.normal, fontColor: ColorsManager.grayColor, ), @@ -79,7 +85,8 @@ class CreateTemporaryPassword extends StatelessWidget { errorBorderColor: Colors.grey, inactiveColor: Colors.grey, inactiveFillColor: Colors.grey, - selectedColor: Colors.grey), + selectedColor: Colors.grey + ), animationDuration: Duration(milliseconds: 300), backgroundColor: Colors.white, enableActiveFill: false, @@ -90,7 +97,9 @@ class CreateTemporaryPassword extends StatelessWidget { width: 10, ), InkWell( - onTap: () {BlocProvider.of(context).generate7DigitNumber();}, + onTap: () { + BlocProvider.of(context).generate7DigitNumber(); + }, child: const BodyMedium( text: 'Generate Randomly', fontWeight: FontWeight.bold, @@ -115,8 +124,11 @@ class CreateTemporaryPassword extends StatelessWidget { trailing: SizedBox( width: MediaQuery.of(context).size.width / 2, child: TextFormField( - controller: BlocProvider.of(context).passwordNameController, - decoration: const InputDecoration(labelText: 'Enter The Name'), + controller: + BlocProvider.of(context) + .passwordNameController, + decoration: const InputDecoration( + labelText: 'Enter The Name'), )), ), const Divider(), @@ -130,10 +142,13 @@ class CreateTemporaryPassword extends StatelessWidget { width: MediaQuery.of(context).size.width / 2, child: InkWell( onTap: () { - BlocProvider.of(context).selectTime(context, isEffective: true); - }, - child: Text(BlocProvider.of(context).effectiveTime), - )) + BlocProvider.of(context) + .selectTime(context, isEffective: true); + }, + child: Text( + BlocProvider.of(context) + .effectiveTime), + )), ), const Divider(), ListTile( @@ -148,9 +163,13 @@ class CreateTemporaryPassword extends StatelessWidget { width: MediaQuery.of(context).size.width / 2, child: InkWell( onTap: () { - BlocProvider.of(context).selectTime(context, isEffective: false); + BlocProvider.of(context) + .selectTime(context, + isEffective: false); }, - child: Text(BlocProvider.of(context).expirationTime), + child: Text( + BlocProvider.of(context) + .expirationTime), )), ), ), @@ -174,7 +193,8 @@ class CreateTemporaryPassword extends StatelessWidget { value: BlocProvider.of(context).repeat, onChanged: (value) { - BlocProvider.of(context).repeatFunction(); + BlocProvider.of(context) + .repeatFunction(); }, applyTheme: true, )), @@ -185,74 +205,73 @@ class CreateTemporaryPassword extends StatelessWidget { ), BlocProvider.of(context).repeat ? DefaultContainer( - padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5), + padding: const EdgeInsets.symmetric( + horizontal: 5, vertical: 5), child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, children: [ InkWell( onTap: () { BlocProvider.of(context).isStartEndTimeFun(true); }, - child: BodyMedium( - text: 'Start', - fontColor: - BlocProvider.of(context).isStartEndTime == false - ? Colors.black : Colors.blue, - fontSize: 18, - ), + child: BodyMedium(text: 'Start',fontColor:BlocProvider.of(context).isStartEndTime==false? Colors.black:Colors.blue,fontSize: 18,), ), + InkWell( onTap: () { BlocProvider.of(context).isStartEndTimeFun(false); - }, - child: BodyMedium( - text: 'End', - fontColor: - BlocProvider.of(context).isStartEndTime - ? Colors.black : Colors.blue, - fontSize: 18, - ), + }, + child: BodyMedium(text: 'End',fontColor:BlocProvider.of(context).isStartEndTime? Colors.black:Colors.blue,fontSize: 18,), ) ], ), ), const Divider(), - SizedBox( + Container( height: 80, - child: BlocProvider.of(context).isStartEndTime - ? TimePickerSpinner( - time: BlocProvider.of(context).startTime, - is24HourMode: false, - itemHeight: 40, - normalTextStyle: const TextStyle( - fontSize: 24, - ), - highlightedTextStyle: const TextStyle( - fontSize: 30, color: Colors.blue), - onTimeChange: (time) { - BlocProvider.of(context).startTime = time; - BlocProvider.of( - context).changeTime(time, BlocProvider.of(context).isStartEndTime); - }, - ) - : TimePickerSpinner( - time: BlocProvider.of(context).endTime, - is24HourMode: false, - itemHeight: 40, - normalTextStyle: const TextStyle( - fontSize: 24, - ), - highlightedTextStyle: const TextStyle( - fontSize: 24, color: Colors.blue), - onTimeChange: (time) { - BlocProvider.of(context).endTime = time; - BlocProvider.of(context).changeTime(time, BlocProvider.of(context).isStartEndTime); - }, - ), + child: BlocProvider.of(context).isStartEndTime? + Container( + height: 90, + child: TimePickerSpinner( + time: + BlocProvider.of(context).startTime, + is24HourMode: false, + itemHeight: 40, + normalTextStyle: const TextStyle( + fontSize: 24, + ), + highlightedTextStyle: const TextStyle( + fontSize: 30, color: Colors.blue), + onTimeChange: (time) { + BlocProvider.of(context).startTime=time; + BlocProvider.of(context).changeTime(time, BlocProvider.of(context).isStartEndTime); + + }, + ), + ): + TimePickerSpinner( + time: BlocProvider.of(context).endTime, + is24HourMode: false, + itemHeight: 40, + normalTextStyle: const TextStyle( + fontSize: 24, + ), + highlightedTextStyle: const TextStyle( + fontSize: 24, color: Colors.blue), + onTimeChange: (time) { + setState(() { + BlocProvider.of(context).endTime=time; + BlocProvider.of(context).changeTime(time, BlocProvider.of(context).isStartEndTime); + + // dateTime = time; + }); + }, + ), ), const Divider(), const SizedBox(height: 20), @@ -287,4 +306,3 @@ class CreateTemporaryPassword extends StatelessWidget { })); } } -