mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 21:57:56 +00:00
Merge pull request #31 from SyncrowIOT/fix_bugs_doorlock
Fix bugs doorlock
This commit is contained in:
@@ -18,6 +18,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
final String deviceId;
|
final String deviceId;
|
||||||
late SmartDoorModel deviceStatus;
|
late SmartDoorModel deviceStatus;
|
||||||
static String pageType = '';
|
static String pageType = '';
|
||||||
|
bool isSavingPassword = false;
|
||||||
|
|
||||||
SmartDoorBloc({required this.deviceId}) : super(InitialState()) {
|
SmartDoorBloc({required this.deviceId}) : super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchSmartDoorStatus);
|
on<InitialEvent>(_fetchSmartDoorStatus);
|
||||||
@@ -184,8 +185,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
|
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||||
CustomSnackBar.displaySnackBar(
|
CustomSnackBar.displaySnackBar('Expiration Time cannot be earlier than Effective Time.');
|
||||||
'Expiration Time cannot be earlier than Effective Time.');
|
|
||||||
} else {
|
} else {
|
||||||
expirationTime =
|
expirationTime =
|
||||||
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
||||||
@@ -198,8 +198,9 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> savePassword(SavePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
Future<void> savePassword(SavePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
if (_validateInputs()) return;
|
if (_validateInputs() || isSavingPassword) return;
|
||||||
try {
|
try {
|
||||||
|
isSavingPassword = true;
|
||||||
emit(LoadingSaveState());
|
emit(LoadingSaveState());
|
||||||
var res = await DevicesAPI.createPassword(
|
var res = await DevicesAPI.createPassword(
|
||||||
pageType: pageType,
|
pageType: pageType,
|
||||||
@@ -220,9 +221,10 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
Navigator.of(event.context).pop(true);
|
Navigator.of(event.context).pop(true);
|
||||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||||
emit(SaveState());
|
emit(SaveState());
|
||||||
} catch (_) {}
|
} catch (_) {}finally {
|
||||||
|
isSavingPassword = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ 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/default_scaffold.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||||
import 'package:time_picker_spinner/time_picker_spinner.dart';
|
import 'package:time_picker_spinner/time_picker_spinner.dart';
|
||||||
@@ -47,14 +48,16 @@ class CreateTemporaryPassword extends StatelessWidget {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop('UpdatePage');
|
Navigator.of(context).pop('UpdatePage');
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.arrow_back)),
|
icon: const Icon(Icons.arrow_back)
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
BlocProvider.of<SmartDoorBloc>(context)
|
BlocProvider.of<SmartDoorBloc>(context)
|
||||||
.add(SavePasswordEvent(context: context));
|
.add(SavePasswordEvent(context: context));
|
||||||
},
|
},
|
||||||
child: const Text('Save'))
|
child: const Text('Save')
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: state is LoadingInitialState
|
child: state is LoadingInitialState
|
||||||
@@ -65,8 +68,7 @@ class CreateTemporaryPassword extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const BodyMedium(
|
const BodyMedium(
|
||||||
text:
|
text: 'Save the password immediately. The password is not displayed in the app.',
|
||||||
'Save the password immediately. The password is not displayed in the app.',
|
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
fontColor: ColorsManager.grayColor,
|
fontColor: ColorsManager.grayColor,
|
||||||
),
|
),
|
||||||
@@ -87,6 +89,12 @@ class CreateTemporaryPassword extends StatelessWidget {
|
|||||||
Flexible(
|
Flexible(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: PinCodeTextField(
|
child: PinCodeTextField(
|
||||||
|
onCompleted: (value) {
|
||||||
|
if (value.split('').every((char) => char == '1')) {
|
||||||
|
BlocProvider.of<SmartDoorBloc>(context).passwordController.clear();
|
||||||
|
CustomSnackBar.displaySnackBar('All characters cannot be 1.');
|
||||||
|
}
|
||||||
|
},
|
||||||
autoDisposeControllers: false,
|
autoDisposeControllers: false,
|
||||||
keyboardType: TextInputType.phone,
|
keyboardType: TextInputType.phone,
|
||||||
length: 7,
|
length: 7,
|
||||||
@@ -107,8 +115,7 @@ class CreateTemporaryPassword extends StatelessWidget {
|
|||||||
animationDuration: const Duration(milliseconds: 300),
|
animationDuration: const Duration(milliseconds: 300),
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
enableActiveFill: false,
|
enableActiveFill: false,
|
||||||
controller:
|
controller: BlocProvider.of<SmartDoorBloc>(context).passwordController,
|
||||||
BlocProvider.of<SmartDoorBloc>(context).passwordController,
|
|
||||||
appContext: context,
|
appContext: context,
|
||||||
)),
|
)),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/model/temporary_password_model.dart';
|
import 'package:syncrow_app/features/devices/model/temporary_password_model.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||||
|
|
||||||
@@ -32,12 +29,12 @@ class DoorDialogState extends State<DoorDialog> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final DateTime effectiveDateTime =
|
final DateTime effectiveDateTime =
|
||||||
DateTime.fromMillisecondsSinceEpoch(widget.value.effectiveTime * 1000, isUtc: true);
|
DateTime.fromMillisecondsSinceEpoch(widget.value.effectiveTime * 1000, isUtc: false);
|
||||||
String formattedDateEffectiveTime = DateFormat('yyyy-MM-dd').format(effectiveDateTime);
|
String formattedDateEffectiveTime = DateFormat('yyyy-MM-dd').format(effectiveDateTime);
|
||||||
String formattedTimeEffectiveTime = DateFormat('HH:mm:ss').format(effectiveDateTime);
|
String formattedTimeEffectiveTime = DateFormat('HH:mm:ss').format(effectiveDateTime);
|
||||||
|
|
||||||
final DateTime expiredDateTime =
|
final DateTime expiredDateTime =
|
||||||
DateTime.fromMillisecondsSinceEpoch(widget.value.invalidTime * 1000, isUtc: true);
|
DateTime.fromMillisecondsSinceEpoch(widget.value.invalidTime * 1000, isUtc: false);
|
||||||
String formattedDateExpiredDateTime = DateFormat('yyyy-MM-dd').format(expiredDateTime);
|
String formattedDateExpiredDateTime = DateFormat('yyyy-MM-dd').format(expiredDateTime);
|
||||||
String formattedTimeExpiredDateTime = DateFormat('HH:mm:ss').format(expiredDateTime);
|
String formattedTimeExpiredDateTime = DateFormat('HH:mm:ss').format(expiredDateTime);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user