Revert "formatted all files."

This reverts commit 04250ebc98.
This commit is contained in:
Faris Armoush
2025-06-12 16:04:49 +03:00
parent 218f43bacb
commit c642ba2644
473 changed files with 4335 additions and 5417 deletions
@@ -14,10 +14,14 @@ import 'package:syncrow_web/pages/visitor_password/model/schedule_model.dart';
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/constants/strings_manager.dart';
import 'package:syncrow_web/utils/constants/temp_const.dart';
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
import 'package:syncrow_web/utils/snack_bar.dart';
class VisitorPasswordBloc
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
on<SelectUsageFrequency>(selectUsageFrequency);
on<FetchDevice>(_onFetchDevice);
@@ -67,13 +71,13 @@ class VisitorPasswordBloc
String startTimeAccess = 'Start Time';
String endTimeAccess = 'End Time';
PasswordStatus? passwordStatus;
void selectAccessType(
selectAccessType(
SelectPasswordType event, Emitter<VisitorPasswordState> emit) {
accessTypeSelected = event.type;
emit(PasswordTypeSelected(event.type));
}
void selectUsageFrequency(
selectUsageFrequency(
SelectUsageFrequency event, Emitter<VisitorPasswordState> emit) {
usageFrequencySelected = event.usageType;
emit(UsageFrequencySelected(event.usageType));
@@ -83,7 +87,7 @@ class VisitorPasswordBloc
SelectTimeVisitorPassword event,
Emitter<VisitorPasswordState> emit,
) async {
final picked = await showDatePicker(
final DateTime? picked = await showDatePicker(
context: event.context,
initialDate: DateTime.now(),
firstDate: DateTime(2015, 8),
@@ -91,7 +95,7 @@ class VisitorPasswordBloc
);
if (picked != null) {
final timePicked = await showTimePicker(
final TimeOfDay? timePicked = await showTimePicker(
context: event.context,
initialTime: TimeOfDay.now(),
builder: (context, child) {
@@ -160,13 +164,13 @@ class VisitorPasswordBloc
}
List<Map<String, String>> days = [
{'day': 'Sun', 'key': 'Sun'},
{'day': 'Mon', 'key': 'Mon'},
{'day': 'Tue', 'key': 'Tue'},
{'day': 'Wed', 'key': 'Wed'},
{'day': 'Thu', 'key': 'Thu'},
{'day': 'Fri', 'key': 'Fri'},
{'day': 'Sat', 'key': 'Sat'},
{"day": "Sun", "key": "Sun"},
{"day": "Mon", "key": "Mon"},
{"day": "Tue", "key": "Tue"},
{"day": "Wed", "key": "Wed"},
{"day": "Thu", "key": "Thu"},
{"day": "Fri", "key": "Fri"},
{"day": "Sat", "key": "Sat"},
];
List<String> selectedDays = [];
@@ -188,12 +192,12 @@ class VisitorPasswordBloc
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
try {
emit(DeviceLoaded());
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
data = await AccessMangApi().fetchDoorLockDeviceList(projectUuid);
emit(TableLoaded(data));
} catch (e) {
print('error: $e');
print("error: $e");
emit(FailedState(e.toString()));
}
}
@@ -204,7 +208,7 @@ class VisitorPasswordBloc
try {
emit(LoadingInitialState());
generate7DigitNumber();
final res = await AccessMangApi().postOnlineOneTime(
var res = await AccessMangApi().postOnlineOneTime(
email: event.email,
password: passwordController,
devicesUuid: selectedDevices,
@@ -218,8 +222,8 @@ class VisitorPasswordBloc
emit(TableLoaded(data));
} on DioException catch (e) {
final errorData = e.response!.data;
final String errorMessage = errorData['message'];
emit(FailedState(errorMessage));
String errorMessage = errorData['message'];
emit(FailedState(errorMessage.toString()));
}
}
@@ -230,12 +234,13 @@ class VisitorPasswordBloc
emit(LoadingInitialState());
await generate7DigitNumber();
final res = await AccessMangApi().postOnlineMultipleTime(
var res = await AccessMangApi().postOnlineMultipleTime(
scheduleList: [
if (repeat)
Schedule(
effectiveTime: getTimeFromDateTimeString(effectiveTime),
invalidTime: getTimeFromDateTimeString(expirationTime),
invalidTime:
getTimeFromDateTimeString(expirationTime).toString(),
workingDay: selectedDays,
),
],
@@ -252,8 +257,8 @@ class VisitorPasswordBloc
emit(TableLoaded(data));
} on DioException catch (e) {
final errorData = e.response!.data;
final String errorMessage = errorData['message'];
emit(FailedState(errorMessage));
String errorMessage = errorData['message'];
emit(FailedState(errorMessage.toString()));
}
}
@@ -263,7 +268,7 @@ class VisitorPasswordBloc
try {
emit(LoadingInitialState());
await generate7DigitNumber();
final res = await AccessMangApi().postOffLineOneTime(
var res = await AccessMangApi().postOffLineOneTime(
email: event.email,
devicesUuid: selectedDevices,
passwordName: event.passwordName);
@@ -274,8 +279,8 @@ class VisitorPasswordBloc
emit(TableLoaded(data));
} on DioException catch (e) {
final errorData = e.response!.data;
final String errorMessage = errorData['message'];
emit(FailedState(errorMessage));
String errorMessage = errorData['message'];
emit(FailedState(errorMessage.toString()));
}
}
@@ -285,7 +290,7 @@ class VisitorPasswordBloc
try {
emit(LoadingInitialState());
await generate7DigitNumber();
final res = await AccessMangApi().postOffLineMultipleTime(
var res = await AccessMangApi().postOffLineMultipleTime(
email: event.email,
devicesUuid: selectedDevices,
passwordName: event.passwordName,
@@ -299,8 +304,8 @@ class VisitorPasswordBloc
emit(TableLoaded(data));
} on DioException catch (e) {
final errorData = e.response!.data;
final String errorMessage = errorData['message'];
emit(FailedState(errorMessage));
String errorMessage = errorData['message'];
emit(FailedState(errorMessage.toString()));
}
}
@@ -322,9 +327,9 @@ class VisitorPasswordBloc
Future generate7DigitNumber() async {
passwordController = '';
final random = Random();
const min = 1000000;
const max = 9999999;
Random random = Random();
int min = 1000000;
int max = 9999999;
passwordController = (min + random.nextInt(max - min + 1)).toString();
return passwordController;
}
@@ -360,7 +365,7 @@ class VisitorPasswordBloc
emit(TableLoaded(event.filteredData));
}
void addDeviceToList(context) {
addDeviceToList(context) {
selectedDevices = selectedDeviceIds;
Navigator.of(context).pop(selectedDevices);
}
@@ -368,14 +373,14 @@ class VisitorPasswordBloc
Future<void> selectTimeOfLinePassword(
SelectTimeEvent event, Emitter<VisitorPasswordState> emit) async {
emit(ChangeTimeState());
final picked = await showDatePicker(
final DateTime? picked = await showDatePicker(
context: event.context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(const Duration(days: 2095)),
);
if (picked != null) {
final timePicked = await showHourPicker(
final TimeOfDay? timePicked = await showHourPicker(
context: event.context,
initialTime: TimeOfDay.now(),
);
@@ -400,7 +405,7 @@ class VisitorPasswordBloc
if (expirationTimeTimeStamp != null &&
selectedTimestamp > expirationTimeTimeStamp!) {
accessPeriodValidate =
'Effective Time cannot be later than Expiration Time.';
"Effective Time cannot be later than Expiration Time.";
} else {
accessPeriodValidate = '';
effectiveTime = selectedDateTime.toString().split('.').first;
@@ -422,7 +427,7 @@ class VisitorPasswordBloc
}
}
void changeTime(ChangeTimeEvent event, Emitter<VisitorPasswordState> emit) {
changeTime(ChangeTimeEvent event, Emitter<VisitorPasswordState> emit) {
if (event.isStartEndTime == true) {
startTime = event.val;
} else {
@@ -432,8 +437,8 @@ class VisitorPasswordBloc
DateTime? convertStringToDateTime(String dateTimeString) {
try {
final inputFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
final dateTime = inputFormat.parse(dateTimeString);
final DateFormat inputFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
DateTime dateTime = inputFormat.parse(dateTimeString);
return dateTime;
} catch (e) {
return null;
@@ -441,7 +446,7 @@ class VisitorPasswordBloc
}
String getTimeFromDateTimeString(String dateTimeString) {
final dateTime = convertStringToDateTime(dateTimeString);
DateTime? dateTime = convertStringToDateTime(dateTimeString);
if (dateTime == null) return '';
return DateFormat('HH:mm').format(dateTime);
}
@@ -140,7 +140,7 @@ class FilterDataEvent extends VisitorPasswordEvent {
class UpdateFilteredDevicesEvent extends VisitorPasswordEvent {
final List<DeviceModel> filteredData;
const UpdateFilteredDevicesEvent(this.filteredData);
UpdateFilteredDevicesEvent(this.filteredData);
}
class SelectTimeEvent extends VisitorPasswordEvent {
@@ -51,8 +51,8 @@ class DeviceModel {
// Deserialize from JSON
factory DeviceModel.fromJson(Map<String, dynamic> json) {
var tempIcon = '';
final type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
String tempIcon = '';
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
if (type == DeviceType.LightBulb) {
tempIcon = Assets.lightBulb;
} else if (type == DeviceType.CeilingSensor ||
@@ -26,6 +26,8 @@ class FailedOperation {
}
}
class SuccessOperation {
final bool success;
// final Result result;
@@ -90,6 +92,8 @@ class SuccessOperation {
// }
// }
class PasswordStatus {
final List<SuccessOperation> successOperations;
final List<FailedOperation> failedOperations;
@@ -117,3 +121,4 @@ class PasswordStatus {
};
}
}
@@ -2,14 +2,15 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/common/access_device_table.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_event.dart';
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_state.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
import 'package:syncrow_web/utils/style.dart';
class AddDeviceDialog extends StatelessWidget {
@@ -17,14 +18,15 @@ class AddDeviceDialog extends StatelessWidget {
const AddDeviceDialog({super.key, this.selectedDeviceIds});
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
Size size = MediaQuery.of(context).size;
return BlocProvider(
create: (context) => VisitorPasswordBloc()..add(FetchDevice()),
create: (context) =>
VisitorPasswordBloc()..add(FetchDevice()),
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
builder: (BuildContext context, VisitorPasswordState state) {
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
if (state is TableLoaded) {
for (final device in selectedDeviceIds!) {
for (var device in selectedDeviceIds!) {
if (selectedDeviceIds!.contains(device)) {
visitorBloc.add(SelectDeviceEvent(device));
}
@@ -52,7 +54,7 @@ class AddDeviceDialog extends StatelessWidget {
padding: const EdgeInsets.all(15),
decoration: containerDecoration.copyWith(
color: ColorsManager.worningColor,
border: Border.all(color: const Color(0xffFFD22F)),
border: Border.all(color: Color(0xffFFD22F)),
boxShadow: []),
child: Row(
children: [
@@ -126,7 +128,9 @@ class AddDeviceDialog extends StatelessWidget {
width: size.width * 0.06,
child: Center(
child: DefaultButton(
onPressed: visitorBloc.filterDevices,
onPressed: () {
visitorBloc.filterDevices();
},
borderRadius: 9,
child: const Text('Search'),
),
@@ -137,7 +141,7 @@ class AddDeviceDialog extends StatelessWidget {
const SizedBox(width: 10),
Expanded(
flex: 2,
child: SizedBox(
child: Container(
width: size.width * 0.06,
child: DefaultButton(
backgroundColor: ColorsManager.whiteColors,
@@ -173,7 +177,7 @@ class AddDeviceDialog extends StatelessWidget {
isEmpty: visitorBloc.data.isEmpty,
selectAll: (p0) {
visitorBloc.selectedDeviceIds.clear();
for (final item in state.data) {
for (var item in state.data) {
visitorBloc
.add(SelectDeviceEvent(item.uuid));
}
@@ -197,7 +201,7 @@ class AddDeviceDialog extends StatelessWidget {
item.uuid.toString(),
item.productType.toString(),
item.spaceName.toString(),
item.online.value,
item.online.value.toString(),
];
}).toList(),
)
@@ -219,7 +223,7 @@ class AddDeviceDialog extends StatelessWidget {
backgroundColor: Colors.white,
child: Text(
'Cancel',
style: Theme.of(context).textTheme.bodyMedium,
style: Theme.of(context).textTheme.bodyMedium!,
),
),
),
@@ -231,7 +235,7 @@ class AddDeviceDialog extends StatelessWidget {
visitorBloc.addDeviceToList(context);
},
borderRadius: 8,
child: const Text('Ok'),
child: Text('Ok'),
),
),
],
@@ -14,7 +14,7 @@ class RepeatWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
Size size = MediaQuery.of(context).size;
return BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
builder: (context, state) {
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
@@ -29,7 +29,7 @@ class RepeatWidget extends StatelessWidget {
children: visitorBloc.days.map((day) {
return Container(
width: 70, // Adjust width as needed
margin: const EdgeInsets.all(5),
margin: EdgeInsets.all(5),
child: CheckboxListTile(
contentPadding: EdgeInsets.zero,
title: Text(
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/common/date_time_widget.dart';
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
@@ -19,11 +20,8 @@ class VisitorPasswordDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final text = Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.black, fontSize: 13);
Size size = MediaQuery.of(context).size;
var text = Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.black, fontSize: 13);
return BlocProvider(
create: (context) => VisitorPasswordBloc(),
child: BlocListener<VisitorPasswordBloc, VisitorPasswordState>(
@@ -37,8 +35,7 @@ class VisitorPasswordDialog extends StatelessWidget {
title: 'Sent Successfully',
widgeta: Column(
children: [
if (visitorBloc
.passwordStatus!.failedOperations.isNotEmpty)
if (visitorBloc.passwordStatus!.failedOperations.isNotEmpty)
Column(
children: [
const Text('Failed Devices'),
@@ -48,26 +45,22 @@ class VisitorPasswordDialog extends StatelessWidget {
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: visitorBloc
.passwordStatus!.failedOperations.length,
itemCount: visitorBloc.passwordStatus!.failedOperations.length,
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.all(5),
margin: EdgeInsets.all(5),
decoration: containerDecoration,
height: 45,
child: Center(
child: Text(visitorBloc
.passwordStatus!
.failedOperations[index]
.deviceUuid)),
.passwordStatus!.failedOperations[index].deviceUuid)),
);
},
),
),
],
),
if (visitorBloc
.passwordStatus!.successOperations.isNotEmpty)
if (visitorBloc.passwordStatus!.successOperations.isNotEmpty)
Column(
children: [
const Text('Success Devices'),
@@ -77,18 +70,15 @@ class VisitorPasswordDialog extends StatelessWidget {
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: visitorBloc
.passwordStatus!.successOperations.length,
itemCount: visitorBloc.passwordStatus!.successOperations.length,
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.all(5),
margin: EdgeInsets.all(5),
decoration: containerDecoration,
height: 45,
child: Center(
child: Text(visitorBloc
.passwordStatus!
.successOperations[index]
.deviceUuid)),
child: Text(visitorBloc.passwordStatus!
.successOperations[index].deviceUuid)),
);
},
),
@@ -99,6 +89,7 @@ class VisitorPasswordDialog extends StatelessWidget {
))
.then((v) {
Navigator.of(context).pop(true);
});
} else if (state is FailedState) {
visitorBloc.stateDialog(
@@ -111,16 +102,15 @@ class VisitorPasswordDialog extends StatelessWidget {
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
builder: (BuildContext context, VisitorPasswordState state) {
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
final isRepeat =
state is IsRepeatState ? state.repeat : visitorBloc.repeat;
bool isRepeat = state is IsRepeatState ? state.repeat : visitorBloc.repeat;
return AlertDialog(
backgroundColor: Colors.white,
title: Text(
'Create visitor password',
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
fontWeight: FontWeight.w400,
fontSize: 24,
color: Colors.black),
style: Theme.of(context)
.textTheme
.headlineLarge!
.copyWith(fontWeight: FontWeight.w400, fontSize: 24, color: Colors.black),
),
content: state is LoadingInitialState
? const Center(child: CircularProgressIndicator())
@@ -138,8 +128,7 @@ class VisitorPasswordDialog extends StatelessWidget {
flex: 2,
child: CustomWebTextField(
validator: visitorBloc.validate,
controller:
visitorBloc.userNameController,
controller: visitorBloc.userNameController,
isRequired: true,
textFieldName: 'Name',
description: '',
@@ -188,26 +177,20 @@ class VisitorPasswordDialog extends StatelessWidget {
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding:
EdgeInsets.zero,
contentPadding: EdgeInsets.zero,
title: Text(
'Online Password',
style: text,
),
value: 'Online Password',
groupValue: (state
is PasswordTypeSelected)
groupValue: (state is PasswordTypeSelected)
? state.selectedType
: visitorBloc
.accessTypeSelected,
: visitorBloc.accessTypeSelected,
onChanged: (String? value) {
if (value != null) {
context
.read<
VisitorPasswordBloc>()
.add(
SelectPasswordType(
value));
.read<VisitorPasswordBloc>()
.add(SelectPasswordType(value));
}
},
),
@@ -215,25 +198,17 @@ class VisitorPasswordDialog extends StatelessWidget {
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding:
EdgeInsets.zero,
title: Text(
'Offline Password',
style: text),
contentPadding: EdgeInsets.zero,
title: Text('Offline Password', style: text),
value: 'Offline Password',
groupValue: (state
is PasswordTypeSelected)
groupValue: (state is PasswordTypeSelected)
? state.selectedType
: visitorBloc
.accessTypeSelected,
: visitorBloc.accessTypeSelected,
onChanged: (String? value) {
if (value != null) {
context
.read<
VisitorPasswordBloc>()
.add(
SelectPasswordType(
value));
.read<VisitorPasswordBloc>()
.add(SelectPasswordType(value));
}
},
),
@@ -267,29 +242,21 @@ class VisitorPasswordDialog extends StatelessWidget {
),
],
),
if (visitorBloc.accessTypeSelected ==
'Online Password')
if (visitorBloc.accessTypeSelected == 'Online Password')
Text(
'Only currently online devices can be selected. It is recommended to use when the device network is stable, and the system randomly generates a digital password',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
),
if (visitorBloc.accessTypeSelected ==
'Offline Password')
if (visitorBloc.accessTypeSelected == 'Offline Password')
Text(
'Unaffected by the online status of the device, you can select online or offline device, and the system randomly generates a digital password',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
),
// if (visitorBloc.accessTypeSelected == 'Dynamic Password')
// Text(
@@ -304,206 +271,143 @@ class VisitorPasswordDialog extends StatelessWidget {
)
],
),
if (visitorBloc.accessTypeSelected ==
'Dynamic Password')
const SizedBox()
else
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
visitorBloc.accessTypeSelected == 'Dynamic Password'
? const SizedBox()
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'* ',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Colors.red),
),
Text(
'Usage Frequency',
style: text,
),
],
),
Row(
children: <Widget>[
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding: EdgeInsets.zero,
title: Text(
'One-Time',
Row(
children: [
Text(
'* ',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Colors.red),
),
Text(
'Usage Frequency',
style: text,
),
value: 'One-Time',
groupValue: (state
is UsageFrequencySelected)
? state.selectedFrequency
: visitorBloc
.usageFrequencySelected,
onChanged: (String? value) {
if (value != null) {
context
.read<VisitorPasswordBloc>()
.add(SelectUsageFrequency(
value));
}
},
),
],
),
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding: EdgeInsets.zero,
title:
Text('Periodic', style: text),
value: 'Periodic',
groupValue: (state
is UsageFrequencySelected)
? state.selectedFrequency
: visitorBloc
.usageFrequencySelected,
onChanged: (String? value) {
if (value != null) {
context
.read<VisitorPasswordBloc>()
.add(SelectUsageFrequency(
value));
}
},
),
Row(
children: <Widget>[
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding: EdgeInsets.zero,
title: Text(
'One-Time',
style: text,
),
value: 'One-Time',
groupValue: (state is UsageFrequencySelected)
? state.selectedFrequency
: visitorBloc.usageFrequencySelected,
onChanged: (String? value) {
if (value != null) {
context
.read<VisitorPasswordBloc>()
.add(SelectUsageFrequency(value));
}
},
),
),
SizedBox(
width: size.width * 0.12,
child: RadioListTile<String>(
contentPadding: EdgeInsets.zero,
title: Text('Periodic', style: text),
value: 'Periodic',
groupValue: (state is UsageFrequencySelected)
? state.selectedFrequency
: visitorBloc.usageFrequencySelected,
onChanged: (String? value) {
if (value != null) {
context.read<VisitorPasswordBloc>()
.add(SelectUsageFrequency(value));
}
},
),
),
],
),
//One-Time
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected == 'Online Password')
Text(
'Within the validity period, each device can be unlocked only once.',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontSize: 9),
),
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected == 'Offline Password')
Text(
'Within the validity period, each device can be unlocked only once, and the maximum validity period is 6 hours',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontSize: 9),
),
// Periodic
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Offline Password')
Text(
'Within the validity period, there is no limit to the number of times each device can be unlocked, and it should be used at least once within 24 hours after the entry into force.',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontSize: 9),
),
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Online Password')
Text(
'Within the validity period, there is no limit to the number of times each device can be unlocked.',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontSize: 9),
),
],
),
//One-Time
if (visitorBloc.usageFrequencySelected ==
'One-Time' &&
visitorBloc.accessTypeSelected ==
'Online Password')
Text(
'Within the validity period, each device can be unlocked only once.',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontSize: 9),
),
if (visitorBloc.usageFrequencySelected ==
'One-Time' &&
visitorBloc.accessTypeSelected ==
'Offline Password')
Text(
'Within the validity period, each device can be unlocked only once, and the maximum validity period is 6 hours',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontSize: 9),
),
// Periodic
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password')
Text(
'Within the validity period, there is no limit to the number of times each device can be unlocked, and it should be used at least once within 24 hours after the entry into force.',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontSize: 9),
),
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Online Password')
Text(
'Within the validity period, there is no limit to the number of times each device can be unlocked.',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor,
fontSize: 9),
),
],
),
const SizedBox(
height: 20,
),
if ((visitorBloc.usageFrequencySelected !=
'One-Time' ||
visitorBloc.accessTypeSelected !=
'Offline Password') &&
if ((visitorBloc.usageFrequencySelected != 'One-Time' ||
visitorBloc.accessTypeSelected != 'Offline Password') &&
(visitorBloc.usageFrequencySelected != ''))
DateTimeWebWidget(
isRequired: true,
title: 'Access Period',
size: size,
endTime: () {
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
visitorBloc.add(SelectTimeEvent(
context: context,
isEffective: false));
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
visitorBloc.add(SelectTimeEvent(context: context, isEffective: false));
} else {
visitorBloc.add(
SelectTimeVisitorPassword(
context: context,
isStart: false,
isRepeat: false));
visitorBloc.add(SelectTimeVisitorPassword(context: context, isStart: false, isRepeat: false));
}
},
startTime: () {
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
visitorBloc.add(SelectTimeEvent(
context: context,
isEffective: true));
} else {
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
visitorBloc.add(
SelectTimeVisitorPassword(
context: context,
isStart: true,
isRepeat: false));
SelectTimeEvent(context: context, isEffective: true));
} else {
visitorBloc.add(SelectTimeVisitorPassword(
context: context, isStart: true, isRepeat: false));
}
},
firstString: (visitorBloc
.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password')
firstString: (visitorBloc.usageFrequencySelected ==
'Periodic' && visitorBloc.accessTypeSelected == 'Offline Password')
? visitorBloc.effectiveTime
: visitorBloc.startTimeAccess,
secondString: (visitorBloc
.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password')
: visitorBloc.startTimeAccess.toString(),
secondString: (visitorBloc.usageFrequencySelected ==
'Periodic' && visitorBloc.accessTypeSelected == 'Offline Password')
? visitorBloc.expirationTime
: visitorBloc.endTimeAccess,
: 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: 10,),
Text(visitorBloc.accessPeriodValidate,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: ColorsManager.red),),
const SizedBox(
height: 20,
),
@@ -527,21 +431,16 @@ class VisitorPasswordDialog extends StatelessWidget {
),
Text(
'Within the validity period, each device can be unlocked only once.',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.grayColor,
fontSize: 9),
),
const SizedBox(
height: 20,
),
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Online Password')
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Online Password')
SizedBox(
width: 100,
child: Column(
@@ -552,8 +451,7 @@ class VisitorPasswordDialog extends StatelessWidget {
child: CupertinoSwitch(
value: visitorBloc.repeat,
onChanged: (value) {
visitorBloc
.add(ToggleRepeatEvent());
visitorBloc.add(ToggleRepeatEvent());
},
applyTheme: true,
),
@@ -561,13 +459,9 @@ class VisitorPasswordDialog extends StatelessWidget {
],
),
),
if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Online Password')
isRepeat
? const RepeatWidget()
: const SizedBox(),
if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Online Password')
isRepeat ? const RepeatWidget() : const SizedBox(),
Container(
decoration: containerDecoration,
width: size.width / 9,
@@ -578,28 +472,22 @@ class VisitorPasswordDialog extends StatelessWidget {
barrierDismissible: false,
builder: (BuildContext context) {
return AddDeviceDialog(
selectedDeviceIds:
visitorBloc.selectedDevices,
selectedDeviceIds: visitorBloc.selectedDevices,
);
},
).then((listDevice) {
if (listDevice != null) {
visitorBloc.selectedDevices =
listDevice;
visitorBloc.selectedDevices = listDevice;
}
});
},
borderRadius: 8,
child: Text(
'+ Add Device',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
fontWeight: FontWeight.w400,
color:
ColorsManager.whiteColors,
fontSize: 12),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w400,
color: ColorsManager.whiteColors,
fontSize: 12),
),
),
),
@@ -637,35 +525,30 @@ class VisitorPasswordDialog extends StatelessWidget {
onPressed: () {
if (visitorBloc.forgetFormKey.currentState!.validate()) {
if (visitorBloc.selectedDevices.isNotEmpty) {
if (visitorBloc.usageFrequencySelected ==
'One-Time' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
setPasswordFunction(context, size, visitorBloc);
} else if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
} else if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
if (visitorBloc.expirationTime != 'End Time' &&
visitorBloc.effectiveTime != 'Start Time') {
visitorBloc.effectiveTime != 'Start Time' ) {
setPasswordFunction(context, size, visitorBloc);
} else {
}else{
visitorBloc.stateDialog(
context: context,
message:
'Please select Access Period to continue',
message: 'Please select Access Period to continue',
title: 'Access Period');
}
} else if (visitorBloc.endTimeAccess != 'End Time' &&
visitorBloc.startTimeAccess != 'Start Time') {
} else if(
visitorBloc.endTimeAccess.toString()!='End Time'
&&visitorBloc.startTimeAccess.toString()!='Start Time') {
if (visitorBloc.effectiveTimeTimeStamp != null &&
visitorBloc.expirationTimeTimeStamp != null) {
if (isRepeat == true) {
if (visitorBloc.expirationTime != 'End Time' &&
visitorBloc.effectiveTime != 'Start Time' &&
visitorBloc.selectedDays.isNotEmpty) {
setPasswordFunction(
context, size, visitorBloc);
setPasswordFunction(context, size, visitorBloc);
} else {
visitorBloc.stateDialog(
context: context,
@@ -679,16 +562,14 @@ class VisitorPasswordDialog extends StatelessWidget {
} else {
visitorBloc.stateDialog(
context: context,
message:
'Please select Access Period to continue',
message: 'Please select Access Period to continue',
title: 'Access Period');
}
} else {
visitorBloc.stateDialog(
context: context,
message:
'Please select Access Period to continue',
title: 'Access Period');
}else{
visitorBloc.stateDialog(
context: context,
message: 'Please select Access Period to continue',
title: 'Access Period');
}
} else {
visitorBloc.stateDialog(
@@ -733,9 +614,8 @@ class VisitorPasswordDialog extends StatelessWidget {
alignment: Alignment.center,
content: SizedBox(
height: size.height * 0.25,
child: const Center(
child:
CircularProgressIndicator(), // Display a loading spinner
child: Center(
child: CircularProgressIndicator(), // Display a loading spinner
),
),
);
@@ -759,10 +639,7 @@ class VisitorPasswordDialog extends StatelessWidget {
),
Text(
'Set Password',
style: Theme.of(context)
.textTheme
.headlineLarge!
.copyWith(
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
fontSize: 30,
fontWeight: FontWeight.w400,
color: Colors.black,
@@ -812,45 +689,37 @@ class VisitorPasswordDialog extends StatelessWidget {
onPressed: () {
Navigator.pop(context);
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected ==
'Online Password') {
visitorBloc.accessTypeSelected == 'Online Password') {
visitorBloc.add(OnlineOneTimePasswordEvent(
context: context,
passwordName: visitorBloc.userNameController.text,
email: visitorBloc.emailController.text,
));
} else if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Online Password') {
}
else if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Online Password') {
visitorBloc.add(OnlineMultipleTimePasswordEvent(
passwordName: visitorBloc.userNameController.text,
email: visitorBloc.emailController.text,
effectiveTime:
visitorBloc.effectiveTimeTimeStamp.toString(),
invalidTime:
visitorBloc.expirationTimeTimeStamp.toString(),
effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(),
invalidTime: visitorBloc.expirationTimeTimeStamp.toString(),
));
} else if (visitorBloc.usageFrequencySelected ==
'One-Time' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
}
else if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
visitorBloc.add(OfflineOneTimePasswordEvent(
context: context,
passwordName: visitorBloc.userNameController.text,
email: visitorBloc.emailController.text,
));
} else if (visitorBloc.usageFrequencySelected ==
'Periodic' &&
visitorBloc.accessTypeSelected ==
'Offline Password') {
}
else if (visitorBloc.usageFrequencySelected == 'Periodic' &&
visitorBloc.accessTypeSelected == 'Offline Password') {
visitorBloc.add(OfflineMultipleTimePasswordEvent(
passwordName: visitorBloc.userNameController.text,
email: visitorBloc.emailController.text,
effectiveTime:
visitorBloc.effectiveTimeTimeStamp.toString(),
invalidTime:
visitorBloc.expirationTimeTimeStamp.toString(),
effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(),
invalidTime: visitorBloc.expirationTimeTimeStamp.toString(),
));
}
},