CreateTemporaryPassword

This commit is contained in:
mohammad
2024-06-29 00:32:19 +03:00
parent 1f93614900
commit 8d6d5da5cd
2 changed files with 84 additions and 67 deletions

View File

@ -24,10 +24,11 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
List<String>? 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<SmartDoorEvent, SmartDoorState> {
}
bool repeatFunction() {
emit(LoadingInitialState());
repeat = !repeat;
emit(IsRepeatState());
return repeat;
@ -195,10 +197,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
);
return;
}
}
//["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
List<DayInWeek> days = [
DayInWeek(
"Sun",

View File

@ -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<CreateTemporaryPassword> createState() =>
_CreateTemporaryPasswordState();
}
class _CreateTemporaryPasswordState extends State<CreateTemporaryPassword> {
@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<SmartDoorBloc>(context).generate7DigitNumber();},
onTap: () {
BlocProvider.of<SmartDoorBloc>(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<SmartDoorBloc>(context).passwordNameController,
decoration: const InputDecoration(labelText: 'Enter The Name'),
controller:
BlocProvider.of<SmartDoorBloc>(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<SmartDoorBloc>(context).selectTime(context, isEffective: true);
},
child: Text(BlocProvider.of<SmartDoorBloc>(context).effectiveTime),
))
BlocProvider.of<SmartDoorBloc>(context)
.selectTime(context, isEffective: true);
},
child: Text(
BlocProvider.of<SmartDoorBloc>(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<SmartDoorBloc>(context).selectTime(context, isEffective: false);
BlocProvider.of<SmartDoorBloc>(context)
.selectTime(context,
isEffective: false);
},
child: Text(BlocProvider.of<SmartDoorBloc>(context).expirationTime),
child: Text(
BlocProvider.of<SmartDoorBloc>(context)
.expirationTime),
)),
),
),
@ -174,7 +193,8 @@ class CreateTemporaryPassword extends StatelessWidget {
value:
BlocProvider.of<SmartDoorBloc>(context).repeat,
onChanged: (value) {
BlocProvider.of<SmartDoorBloc>(context).repeatFunction();
BlocProvider.of<SmartDoorBloc>(context)
.repeatFunction();
},
applyTheme: true,
)),
@ -185,74 +205,73 @@ class CreateTemporaryPassword extends StatelessWidget {
),
BlocProvider.of<SmartDoorBloc>(context).repeat
? DefaultContainer(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
padding: const EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
BlocProvider.of<SmartDoorBloc>(context).isStartEndTimeFun(true);
},
child: BodyMedium(
text: 'Start',
fontColor:
BlocProvider.of<SmartDoorBloc>(context).isStartEndTime == false
? Colors.black : Colors.blue,
fontSize: 18,
),
child: BodyMedium(text: 'Start',fontColor:BlocProvider.of<SmartDoorBloc>(context).isStartEndTime==false? Colors.black:Colors.blue,fontSize: 18,),
),
InkWell(
onTap: () {
BlocProvider.of<SmartDoorBloc>(context).isStartEndTimeFun(false);
},
child: BodyMedium(
text: 'End',
fontColor:
BlocProvider.of<SmartDoorBloc>(context).isStartEndTime
? Colors.black : Colors.blue,
fontSize: 18,
),
},
child: BodyMedium(text: 'End',fontColor:BlocProvider.of<SmartDoorBloc>(context).isStartEndTime? Colors.black:Colors.blue,fontSize: 18,),
)
],
),
),
const Divider(),
SizedBox(
Container(
height: 80,
child: BlocProvider.of<SmartDoorBloc>(context).isStartEndTime
? TimePickerSpinner(
time: BlocProvider.of<SmartDoorBloc>(context).startTime,
is24HourMode: false,
itemHeight: 40,
normalTextStyle: const TextStyle(
fontSize: 24,
),
highlightedTextStyle: const TextStyle(
fontSize: 30, color: Colors.blue),
onTimeChange: (time) {
BlocProvider.of<SmartDoorBloc>(context).startTime = time;
BlocProvider.of<SmartDoorBloc>(
context).changeTime(time, BlocProvider.of<SmartDoorBloc>(context).isStartEndTime);
},
)
: TimePickerSpinner(
time: BlocProvider.of<SmartDoorBloc>(context).endTime,
is24HourMode: false,
itemHeight: 40,
normalTextStyle: const TextStyle(
fontSize: 24,
),
highlightedTextStyle: const TextStyle(
fontSize: 24, color: Colors.blue),
onTimeChange: (time) {
BlocProvider.of<SmartDoorBloc>(context).endTime = time;
BlocProvider.of<SmartDoorBloc>(context).changeTime(time, BlocProvider.of<SmartDoorBloc>(context).isStartEndTime);
},
),
child: BlocProvider.of<SmartDoorBloc>(context).isStartEndTime?
Container(
height: 90,
child: TimePickerSpinner(
time:
BlocProvider.of<SmartDoorBloc>(context).startTime,
is24HourMode: false,
itemHeight: 40,
normalTextStyle: const TextStyle(
fontSize: 24,
),
highlightedTextStyle: const TextStyle(
fontSize: 30, color: Colors.blue),
onTimeChange: (time) {
BlocProvider.of<SmartDoorBloc>(context).startTime=time;
BlocProvider.of<SmartDoorBloc>(context).changeTime(time, BlocProvider.of<SmartDoorBloc>(context).isStartEndTime);
},
),
):
TimePickerSpinner(
time: BlocProvider.of<SmartDoorBloc>(context).endTime,
is24HourMode: false,
itemHeight: 40,
normalTextStyle: const TextStyle(
fontSize: 24,
),
highlightedTextStyle: const TextStyle(
fontSize: 24, color: Colors.blue),
onTimeChange: (time) {
setState(() {
BlocProvider.of<SmartDoorBloc>(context).endTime=time;
BlocProvider.of<SmartDoorBloc>(context).changeTime(time, BlocProvider.of<SmartDoorBloc>(context).isStartEndTime);
// dateTime = time;
});
},
),
),
const Divider(),
const SizedBox(height: 20),
@ -287,4 +306,3 @@ class CreateTemporaryPassword extends StatelessWidget {
}));
}
}