Compare commits

..

8 Commits

Author SHA1 Message Date
0ac3e79c30 new HourPicker 2024-09-12 14:18:53 +03:00
dbb3450c32 new HourPicker 2024-09-11 16:04:54 +03:00
8c3df39cf4 fix changes 2024-09-09 12:44:55 +03:00
7f862fac2a fix changes 2024-09-09 14:51:06 +03:00
770db5383b fix changes 2024-09-09 13:36:26 +03:00
eddd4828bb Merge pull request #18 from SyncrowIOT/web_changes_1
fix changes
2024-09-09 13:12:22 +03:00
2162c996ea fix changes 2024-09-09 13:03:37 +03:00
177baca864 Merge pull request #16 from SyncrowIOT/otp_changes
curtain and forget password and select all check box and fix bugs
2024-09-08 23:15:20 +03:00
9 changed files with 507 additions and 415 deletions

View File

@ -34,6 +34,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final TextEditingController forgetPasswordController = TextEditingController();
final TextEditingController forgetOtp = TextEditingController();
final forgetFormKey = GlobalKey<FormState>();
final forgetEmailKey = GlobalKey<FormState>();
final forgetRegionKey = GlobalKey<FormState>();
late bool checkValidate = false;
Timer? _timer;
@ -93,34 +95,36 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
}
Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
try {
emit(LoadingForgetState());
var response = await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text);
if (response == true) {
await AuthenticationAPI.forgetPassword(
password: forgetPasswordController.text, email: forgetEmailController.text);
_timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState());
emit(LoadingForgetState());
try {
var response = await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text);
if (response == true) {
await AuthenticationAPI.forgetPassword(
password: forgetPasswordController.text,
email: forgetEmailController.text);
_timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState());
}
} on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if (errorMessage == 'this email is not registered') {
validate = 'Invalid Credentials!';
emit(AuthInitialState());
} else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.';
emit(AuthInitialState());
} else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.';
emit(AuthInitialState());
} else {
validate = '';
emit(AuthInitialState());
}
}
} on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if (errorMessage == 'this email is not registered') {
validate = 'Invalid Credentials!';
emit(AuthInitialState());
} else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.';
emit(AuthInitialState());
} else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.';
emit(AuthInitialState());
} else {
validate = '';
emit(AuthInitialState());
}
}
}
String? validateCode(String? value) {
@ -231,9 +235,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return 'Email is required';
} else if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) {
return 'Enter a valid email address';
} else if (regionUuid == '') {
return 'Please select your region';
}
// else if (regionUuid == '') {
// return 'Please select your region';
// }
validate = '';
return null;
}
@ -371,6 +376,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
try {
emit(AuthLoading());
regionUuid = event.val;
add(CheckEnableEvent());
emit(AuthInitialState());
} catch (e) {
emit(FailureForgetState(error: e.toString()));

View File

@ -64,91 +64,96 @@ class ForgetPasswordWebPage extends StatelessWidget {
Size size = MediaQuery.of(context).size;
return FirstLayer(
second: Center(
child: Stack(
child: Stack(
children: [
if (state is AuthLoading)
const Center(child: CircularProgressIndicator()),
ListView(
shrinkWrap: true,
controller: _scrollController,
children: [
if (state is AuthLoading)
const Center(child: CircularProgressIndicator()),
ListView(
shrinkWrap: true,
controller: _scrollController,
children: [
Container(
padding: EdgeInsets.all(size.width * 0.02),
margin: EdgeInsets.all(size.width * 0.09),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.3),
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
Expanded(
flex: 3,
child: SvgPicture.asset(
Assets.loginLogo,
),
),
const Spacer(),
Expanded(
flex: 3,
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius:
Container(
padding: EdgeInsets.all(size.width * 0.02),
margin: EdgeInsets.all(size.width * 0.09),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.3),
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
Expanded(
flex: 3,
child: SvgPicture.asset(
Assets.loginLogo,
),
),
const Spacer(),
Expanded(
flex: 3,
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius:
const BorderRadius.all(Radius.circular(30)),
border: Border.all(
color:
border: Border.all(
color:
ColorsManager.graysColor.withOpacity(0.2)),
),
child: Form(
key: forgetBloc.forgetFormKey,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.02,
vertical: size.width * 0.003),
child: Column(
mainAxisAlignment:
),
child: Form(
key: forgetBloc.forgetFormKey,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.02,
vertical: size.width * 0.003),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 10),
const Text(
'Forget Password',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Text(
'Please fill in your account information to\nretrieve your password',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 10),
const Text(
'Forget Password',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Text(
'Please fill in your account information to\nretrieve your password',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
),
),
const SizedBox(height: 10),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(height: 10),
Column(
Form(
key: forgetBloc.forgetRegionKey,
child: SizedBox(
child: _buildDropdownField(
context, forgetBloc, size)))
],
),
const SizedBox(height: 20),
Form(
key: forgetBloc.forgetEmailKey,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(height: 10),
SizedBox(
child: _buildDropdownField(context, forgetBloc, size)
)
],
),
const SizedBox(height: 20),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text(
"Account",
@ -156,17 +161,20 @@ class ForgetPasswordWebPage extends StatelessWidget {
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
fontSize: 14,
fontWeight:
FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
controller:forgetBloc.forgetEmailController ,
controller: forgetBloc.forgetEmailController,
validator: forgetBloc.validateEmail,
decoration: textBoxDecoration()!.copyWith(
decoration:
textBoxDecoration()!.copyWith(
hintText: 'Enter your email',
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
hintStyle: Theme.of(context)
.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
),
@ -174,200 +182,237 @@ class ForgetPasswordWebPage extends StatelessWidget {
color: Colors.black),
),
),
if(forgetBloc.forgetEmailValidate!='')
SizedBox(
child: Text(
forgetBloc.forgetEmailValidate,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: ColorsManager.red),
),
),
const SizedBox(height: 10.0),
],
),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
)),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"One Time Password",
style: Theme.of(context)
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"One Time Password",
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.validateCode,
keyboardType:
TextInputType.visiblePassword,
controller: forgetBloc.forgetOtp,
decoration:
textBoxDecoration()!.copyWith(
hintText: 'Enter Code',
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.validateCode,
keyboardType:
TextInputType.visiblePassword,
controller: forgetBloc.forgetOtp,
decoration:
textBoxDecoration()!.copyWith(
hintText: 'Enter Code',
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
suffixIcon: SizedBox(
width: 100,
child: Center(
child: InkWell(
onTap: state is TimerState &&
!state.isButtonEnabled &&
state.remainingTime != 1
? null : () {
forgetBloc.add(StartTimerEvent());
},
child: Text(
'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}',
style: TextStyle(
color: state is TimerState &&
!state.isButtonEnabled
? Colors.grey
: ColorsManager.btnColor,
),
),
color:
ColorsManager.grayColor,
fontWeight:
FontWeight.w400),
suffixIcon: SizedBox(
width: 100,
child: Center(
child: InkWell(
onTap: state is TimerState &&
!state
.isButtonEnabled &&
state.remainingTime !=
1
? null
: () {
if (forgetBloc.forgetEmailKey.currentState!.validate()||forgetBloc.forgetRegionKey.currentState!.validate()) {
if(forgetBloc.forgetRegionKey.currentState!.validate()){
forgetBloc.add(StartTimerEvent());
}
}
},
child: Text(
'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}',
style: TextStyle(
color: state
is TimerState &&
!state
.isButtonEnabled
? Colors.grey
: ColorsManager
.btnColor,
),
),
),
),
style: const TextStyle(
color: Colors.black),
),
),
if (forgetBloc.forgetValidate != '') // Check if there is a validation message
Padding(
padding:
style: const TextStyle(
color: Colors.black),
),
),
if (forgetBloc.forgetValidate !=
'') // Check if there is a validation message
Padding(
padding:
const EdgeInsets.only(top: 8.0),
child: Text(
forgetBloc.forgetValidate,
style: const TextStyle(
color: ColorsManager.red,
fontSize: 10,
fontWeight: FontWeight.w700),
child: Text(
forgetBloc.forgetValidate,
style: const TextStyle(
color: ColorsManager.red,
fontSize: 10,
fontWeight: FontWeight.w700),
),
),
],
),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"Password",
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
obscureText: forgetBloc.obscureText,
keyboardType:
TextInputType.visiblePassword,
validator:
forgetBloc.passwordValidator,
controller: forgetBloc
.forgetPasswordController,
decoration:
textBoxDecoration()!.copyWith(
suffixIcon: IconButton(
onPressed: () {
forgetBloc.add(
PasswordVisibleEvent(
newValue: forgetBloc
.obscureText));
},
icon: SizedBox(
child: SvgPicture.asset(
forgetBloc.obscureText
? Assets.visiblePassword
: Assets
.invisiblePassword,
height: 15,
width: 15,
),
),
),
],
),
const SizedBox(height: 20.0),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"Password",
style: Theme.of(context)
hintText: 'At least 8 characters',
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.passwordValidator,
keyboardType: TextInputType.visiblePassword,
controller: forgetBloc.forgetPasswordController,
decoration: textBoxDecoration()!.copyWith(
hintText: 'At least 8 characters',
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400),
),
style: const TextStyle(color: Colors.black),
),
),
],
),
const SizedBox(
height: 10,
),
const SizedBox(height: 20.0),
Row(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: size.width * 0.2,
child: DefaultButton(
backgroundColor:
ColorsManager.btnColor,
child: const Text('Submit'),
onPressed: () {
if (forgetBloc.forgetFormKey.currentState!.validate()) {
forgetBloc.add(ChangePasswordEvent());
}
},
),
),
],
),
const SizedBox(height: 10.0),
Center(
child: SizedBox(
child: Text(
forgetBloc.validate,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: ColorsManager.red),
color:
ColorsManager.grayColor,
fontWeight:
FontWeight.w400),
),
style: const TextStyle(
color: Colors.black),
),
),
const SizedBox(
height: 10,
),
SizedBox(
child: Center(
child: Wrap(
children: [
const Text(
"Do you have an account? ",
style: TextStyle(color: Colors.white),
),
InkWell(
onTap: () {
forgetBloc.add(StopTimerEvent());
Navigator.pop(context);
},
child: const Text(
"Sign in",
),
),
],
),
),
),
const SizedBox(height: 15.0),
],
),
),
const SizedBox(
height: 10,
),
const SizedBox(height: 20.0),
Row(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: size.width * 0.2,
child: DefaultButton(
backgroundColor:
ColorsManager.btnColor,
child: const Text('Submit'),
onPressed: () {
if (forgetBloc.forgetFormKey.currentState!.validate() ||
forgetBloc.forgetEmailKey.currentState!.validate() ) {
if( forgetBloc.forgetEmailKey.currentState!.validate()
&&forgetBloc.forgetFormKey.currentState!.validate() ){
forgetBloc.add(ChangePasswordEvent());
}
}
},
),
),
],
),
const SizedBox(height: 10.0),
Center(
child: SizedBox(
child: Text(
forgetBloc.validate,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: ColorsManager.red),
),
),
),
const SizedBox(
height: 10,
),
SizedBox(
child: Center(
child: Wrap(
children: [
const Text(
"Do you have an account? ",
style:
TextStyle(color: Colors.white),
),
InkWell(
onTap: () {
forgetBloc.add(StopTimerEvent());
Navigator.pop(context);
},
child: const Text(
"Sign in",
),
),
],
),
),
),
const SizedBox(height: 15.0),
],
),
),
),
const Spacer(),
],
),
),
),
const Spacer(),
],
),
],
),
),
],
),
));
],
),
));
}
Widget _buildDropdownField(
BuildContext context, AuthBloc loginBloc, Size size) {
final TextEditingController textEditingController = TextEditingController();
@ -378,100 +423,153 @@ class ForgetPasswordWebPage extends StatelessWidget {
Text(
"Country/Region",
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
Container(
height: 50,
decoration: const BoxDecoration(
color: ColorsManager.boxColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
),
SizedBox(
width: size.width * 0.9,
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
style: TextStyle(color: Colors.black),
isExpanded: true,
hint: Text(
'Select your region/country',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
overflow: TextOverflow.ellipsis,
),
items: loginBloc.regionList!.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id, // Use region.id as the value
child: Text(
region.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
child: FormField<String>(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please select a country/region';
}
return null;
},
builder: (FormFieldState<String> field) {
return InputDecorator(
decoration: InputDecoration(
contentPadding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 10),
errorText: field.errorText,
filled:
true, // Ensure the dropdown is filled with the background color
fillColor: ColorsManager
.boxColor, // Match the dropdown container color
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: field.hasError ? Colors.red : Colors.transparent,
width: 1.5,
),
),
);
}).toList(),
value: loginBloc.regionList!.any(
(region) => region.id == loginBloc.regionUuid,)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
if (value != null) {
loginBloc.add(SelectRegionEvent(
val: value,
));
}
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.symmetric(horizontal: 16),
height: 40,
width: double.infinity,
),
dropdownStyleData: DropdownStyleData(
maxHeight: size.height * 0.70,
),
menuItemStyleData: const MenuItemStyleData(
height: 40,
),
dropdownSearchData: DropdownSearchData(
searchController: textEditingController,
searchInnerWidgetHeight: 50,
searchInnerWidget: Container(
height: 50,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: TextFormField(
style: const TextStyle(color: Colors.black),
controller: textEditingController,
decoration: textBoxDecoration()!.copyWith(
errorStyle: const TextStyle(height: 0),
contentPadding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 10,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color:
field.hasError ? Colors.red : ColorsManager.grayColor,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color:
field.hasError ? Colors.red : ColorsManager.grayColor,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
searchMatchFn: (item, searchValue) {
// Use the item's child text (region name) for searching.
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
final search = searchValue.toLowerCase().trim();
// Debugging print statement to ensure values are captured correctly.
// Return true if the region name contains the search term.
return regionName.contains(search);
},
),
onMenuStateChange: (isOpen) {
if (!isOpen) {
textEditingController.clear();
}
},
),
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
isExpanded: true,
hint: Text(
'Select your region/country',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
overflow: TextOverflow.ellipsis,
),
items: loginBloc.regionList!.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id,
child: Text(
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
region.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
);
}).toList(),
value: loginBloc.regionList!
.any((region) => region.id == loginBloc.regionUuid)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
if (value != null) {
loginBloc.add(SelectRegionEvent(val: value));
field.didChange(
value); // Notify the form field of the change
}
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.symmetric(horizontal: 16),
height: 40,
width: double.infinity,
),
dropdownStyleData: DropdownStyleData(
maxHeight: size.height * 0.70,
decoration: BoxDecoration(
color: ColorsManager
.boxColor, // Match dropdown background color to the container
borderRadius: BorderRadius.circular(8.0),
),
),
menuItemStyleData: const MenuItemStyleData(
height: 40,
),
dropdownSearchData: DropdownSearchData(
searchController: textEditingController,
searchInnerWidgetHeight: 50,
searchInnerWidget: Container(
height: 50,
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
child: TextFormField(
style: const TextStyle(color: Colors.black),
controller: textEditingController,
decoration: textBoxDecoration()!.copyWith(
errorStyle: const TextStyle(height: 0),
contentPadding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 10,
),
),
),
),
searchMatchFn: (item, searchValue) {
final regionName =
(item.child as Text).data?.toLowerCase() ?? '';
final search = searchValue.toLowerCase().trim();
return regionName.contains(search);
},
),
onMenuStateChange: (isOpen) {
if (!isOpen) {
textEditingController.clear();
}
},
),
),
);
},
),
),
],
);
}
}

View File

@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
class HourPickerDialog extends StatefulWidget {
final TimeOfDay initialTime;
const HourPickerDialog({super.key, required this.initialTime});
@override
@ -9,70 +12,50 @@ class HourPickerDialog extends StatefulWidget {
}
class _HourPickerDialogState extends State<HourPickerDialog> {
late int _selectedHour;
bool _isPm = false;
late String selectedHour;
@override
void initState() {
super.initState();
_selectedHour = widget.initialTime.hour > 12
? widget.initialTime.hour - 12
: widget.initialTime.hour;
_isPm = widget.initialTime.period == DayPeriod.pm;
// Initialize the selectedHour with the initial time passed to the dialog
selectedHour = widget.initialTime.hour.toString().padLeft(2, '0') + ':00';
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Select Hour'),
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DropdownButton<int>(
value: _selectedHour,
items: List.generate(12, (index) {
int displayHour = index + 1;
return DropdownMenuItem(
value: displayHour,
child: Text(displayHour.toString()),
);
}),
onChanged: (value) {
setState(() {
_selectedHour = value!;
});
},
),
SizedBox(width: 16.0),
DropdownButton<bool>(
value: _isPm,
items: const [
DropdownMenuItem(
value: true,
child: Text('AM'),
),
DropdownMenuItem(
value:false ,
child: Text('PM'),
),
],
onChanged: (value) {
setState(() {
_isPm = value!;
});
},
),
],
content: DropdownButton<String>(
value: selectedHour, // Show the currently selected hour
items: List.generate(24, (index) {
String hour = index.toString().padLeft(2, '0');
return DropdownMenuItem<String>(
value: '$hour:00',
child: Text('$hour:00'),
);
}),
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedHour = newValue; // Update the selected hour without closing the dialog
});
}
},
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(null),
onPressed: () => Navigator.of(context).pop(null), // Close the dialog without selection
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
int hour = _isPm ? _selectedHour + 12 : _selectedHour;
Navigator.of(context).pop(TimeOfDay(hour: hour, minute: 0));
// Close the dialog and return the selected time
Navigator.of(context).pop(
TimeOfDay(
hour: int.parse(selectedHour.split(':')[0]),
minute: 0,
),
);
},
child: const Text('OK'),
),
@ -86,6 +69,7 @@ Future<TimeOfDay?> showHourPicker({
required TimeOfDay initialTime,
}) {
return showDialog<TimeOfDay>(
barrierDismissible: false,
context: context,
builder: (context) => HourPickerDialog(initialTime: initialTime),
);

View File

@ -69,7 +69,7 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
deviceId: device.uuid!,
description: 'Child Lock',
icon:
state.status.childLock ? Assets.unlock : Assets.childLock,
state.status.childLock ? Assets.childLock:Assets.unlock ,
),
],
);

View File

@ -116,7 +116,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
? const EdgeInsets.all(30)
: const EdgeInsets.all(15),
child: DynamicTable(
withSelectAll: true,
withSelectAll: false,
cellDecoration: containerDecoration,
onRowSelected: (index, isSelected, row) {
final selectedDevice = devicesToShow[index];

View File

@ -14,6 +14,7 @@ import 'package:syncrow_web/services/access_mang_api.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/snack_bar.dart';
import 'package:syncrow_web/utils/style.dart';
class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
@ -32,9 +33,9 @@ class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordStat
on<SelectTimeEvent>(selectTimeOfLinePassword);
on<ChangeTimeEvent>(changeTime);
}
final TextEditingController userNameController = TextEditingController();
final TextEditingController emailController = TextEditingController();
final TextEditingController deviceNameController = TextEditingController();
final TextEditingController deviceIdController = TextEditingController();
final TextEditingController unitNameController = TextEditingController();
@ -51,6 +52,7 @@ class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordStat
String accessTypeSelected = 'Online Password';
String usageFrequencySelected = 'One-Time';
String passwordController = '';
String accessPeriodValidate = '';
bool repeat = false;
@ -377,19 +379,18 @@ class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordStat
1000; // Divide by 1000 to remove milliseconds
if (event.isEffective) {
if (expirationTimeTimeStamp != null && selectedTimestamp > expirationTimeTimeStamp!) {
CustomSnackBar.displaySnackBar('Effective Time cannot be later than Expiration Time.');
accessPeriodValidate="Effective Time cannot be later than Expiration Time.";
} else {
effectiveTime =
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
accessPeriodValidate='';
effectiveTime = selectedDateTime.toString().split('.').first;
effectiveTimeTimeStamp = selectedTimestamp;
}
} else {
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
CustomSnackBar.displaySnackBar(
'Expiration Time cannot be earlier than Effective Time.');
accessPeriodValidate= 'Expiration Time cannot be earlier than Effective Time.';
} else {
expirationTime =
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
accessPeriodValidate='';
expirationTime = selectedDateTime.toString().split('.').first;
expirationTimeTimeStamp = selectedTimestamp;
}
}

View File

@ -404,6 +404,9 @@ class VisitorPasswordDialog extends StatelessWidget {
? visitorBloc.expirationTime
: visitorBloc.endTimeAccess.toString(),
icon: Assets.calendarIcon),
const SizedBox(height: 10,),
Text(visitorBloc.accessPeriodValidate,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: ColorsManager.red),),
const SizedBox(
height: 20,
),

View File

@ -41,3 +41,4 @@ BoxDecoration containerDecoration = BoxDecoration(
],
color: ColorsManager.boxColor,
borderRadius: const BorderRadius.all(Radius.circular(10)));

View File

@ -50,7 +50,6 @@ dependencies:
dropdown_search: ^5.0.6
flutter_dotenv: ^5.1.0
dev_dependencies:
flutter_test:
sdk: flutter