Merge pull request #112 from SyncrowIOT/SP-368-clarification-on-default-value-for-start-date-in-door-lock-online-tile-limited-password-repeat-section

Clarification on Default Value for Start Date in Door Lock Online Tile Limited Password repeat section
This commit is contained in:
Rafeek-khoudare
2025-07-02 09:12:48 +03:00
committed by GitHub
3 changed files with 222 additions and 138 deletions

View File

@ -354,6 +354,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
Future<void> selectTimeOnlinePassword( Future<void> selectTimeOnlinePassword(
SelectTimeOnlinePasswordEvent event, Emitter<SmartDoorState> emit) async { SelectTimeOnlinePasswordEvent event, Emitter<SmartDoorState> emit) async {
effectiveTimeTimeStamp ??= DateTime.now().millisecondsSinceEpoch ~/ 1000;
emit(ChangeTimeState()); emit(ChangeTimeState());
final DateTime? picked = await showDatePicker( final DateTime? picked = await showDatePicker(
context: event.context, context: event.context,
@ -398,7 +399,13 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
selectedDateTime.minute, selectedDateTime.minute,
).millisecondsSinceEpoch ~/ ).millisecondsSinceEpoch ~/
1000; // Divide by 1000 to remove milliseconds 1000; // Divide by 1000 to remove milliseconds
final currentTimestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
if (event.isEffective) { if (event.isEffective) {
if (selectedTimestamp < currentTimestamp) {
CustomSnackBar.displaySnackBar(
'Effective Time cannot be later than Expiration Time.');
return;
}
if (expirationTimeTimeStamp != null && if (expirationTimeTimeStamp != null &&
selectedTimestamp > expirationTimeTimeStamp!) { selectedTimestamp > expirationTimeTimeStamp!) {
CustomSnackBar.displaySnackBar( CustomSnackBar.displaySnackBar(

View File

@ -11,6 +11,9 @@ class NameTimeWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
DateTime now = DateTime.now();
DateTime cleaned =
DateTime(now.year, now.month, now.day, now.hour, now.minute);
return DefaultContainer( return DefaultContainer(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
child: Column( child: Column(
@ -59,19 +62,22 @@ class NameTimeWidget extends StatelessWidget {
width: MediaQuery.of(context).size.width / 3.5, width: MediaQuery.of(context).size.width / 3.5,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
BlocProvider.of<SmartDoorBloc>(context).add(
BlocProvider.of<SmartDoorBloc>(context).add(SelectTimeOnlinePasswordEvent(context: context, isEffective: true)); SelectTimeOnlinePasswordEvent(
context: context, isEffective: true));
}, },
child: Text( child: Text(
BlocProvider.of<SmartDoorBloc>(context).effectiveTime, BlocProvider.of<SmartDoorBloc>(context)
style: TextStyle(fontSize: 14, .effectiveTime ==
color: BlocProvider.of<SmartDoorBloc>(context).effectiveTime ==
'Select Time' 'Select Time'
? ColorsManager.textGray ? cleaned.toString()
: null), : BlocProvider.of<SmartDoorBloc>(context)
.effectiveTime,
style: TextStyle(fontSize: 14),
), ),
)), )),
],), ],
),
), ),
const Divider( const Divider(
color: ColorsManager.graysColor, color: ColorsManager.graysColor,
@ -96,10 +102,13 @@ class NameTimeWidget extends StatelessWidget {
context: context, isEffective: false)); context: context, isEffective: false));
}, },
child: Text( child: Text(
BlocProvider.of<SmartDoorBloc>(context).expirationTime, BlocProvider.of<SmartDoorBloc>(context)
.expirationTime,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: BlocProvider.of<SmartDoorBloc>(context).expirationTime == 'Select Time' color: BlocProvider.of<SmartDoorBloc>(context)
.expirationTime ==
'Select Time'
? ColorsManager.textGray ? ColorsManager.textGray
: null), : null),
), ),

View File

@ -18,7 +18,8 @@ import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
class CreateOfflineTimeLimitPasswordPage extends StatelessWidget { class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
final String? deviceId; final String? deviceId;
final String? type; final String? type;
const CreateOfflineTimeLimitPasswordPage({super.key, this.deviceId, this.type}); const CreateOfflineTimeLimitPasswordPage(
{super.key, this.deviceId, this.type});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool isRepeat = false; bool isRepeat = false;
@ -28,9 +29,7 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
child: BlocConsumer<SmartDoorBloc, SmartDoorState>( child: BlocConsumer<SmartDoorBloc, SmartDoorState>(
listener: (context, state) { listener: (context, state) {
if (state is FailedState) { if (state is FailedState) {
CustomSnackBar.displaySnackBar( CustomSnackBar.displaySnackBar(state.errorMessage);
state.errorMessage
);
} }
if (state is IsRepeatState) { if (state is IsRepeatState) {
isRepeat = state.repeat; isRepeat = state.repeat;
@ -39,6 +38,10 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
generated = state.generated; generated = state.generated;
} }
}, builder: (context, state) { }, builder: (context, state) {
DateTime now = DateTime.now();
DateTime cleaned =
DateTime(now.year, now.month, now.day, now.hour, now.minute);
final smartDoorBloc = BlocProvider.of<SmartDoorBloc>(context); final smartDoorBloc = BlocProvider.of<SmartDoorBloc>(context);
return DefaultScaffold( return DefaultScaffold(
appBar: AppBar( appBar: AppBar(
@ -85,8 +88,9 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
Flexible( Flexible(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: smartDoorBloc.passwordController.text.isEmpty ? children: smartDoorBloc
List.generate(10, (index) { .passwordController.text.isEmpty
? List.generate(10, (index) {
return const Padding( return const Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: 4.0, horizontal: 4.0,
@ -97,30 +101,39 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
color: Colors.black, color: Colors.black,
), ),
); );
}) : [ })
: [
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: BodyLarge( child: BodyLarge(
style: const TextStyle( style: const TextStyle(
color: ColorsManager.primaryColor, color: ColorsManager
fontWeight: FontWeight.bold, .primaryColor,
fontWeight:
FontWeight.bold,
letterSpacing: 8.0, letterSpacing: 8.0,
fontSize: 25, fontSize: 25,
wordSpacing: 2), wordSpacing: 2),
textAlign: TextAlign.center, textAlign:
text: smartDoorBloc.passwordController.text, TextAlign.center,
text: smartDoorBloc
.passwordController
.text,
fontSize: 25, fontSize: 25,
), ),
), ),
IconButton( IconButton(
onPressed: () async { onPressed: () async {
await Clipboard.setData( await Clipboard.setData(
ClipboardData(text: smartDoorBloc.passwordController.text) ClipboardData(
); text: smartDoorBloc
.passwordController
.text));
}, },
icon: const Icon(Icons.copy)), icon: const Icon(
Icons.copy)),
], ],
), ),
), ),
@ -136,11 +149,13 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
Expanded( Expanded(
child: Container( child: Container(
padding: const EdgeInsets.all(10.0), padding:
const EdgeInsets.all(10.0),
child: const BodyMedium( child: const BodyMedium(
text: 'Password Name', text: 'Password Name',
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
@ -148,47 +163,78 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
), ),
), ),
SizedBox( SizedBox(
width: MediaQuery.of(context).size.width / 2.6, width: MediaQuery.of(context)
.size
.width /
2.6,
child: TextFormField( child: TextFormField(
controller: BlocProvider.of<SmartDoorBloc>(context).passwordNameController, controller: BlocProvider.of<
SmartDoorBloc>(context)
.passwordNameController,
decoration: decoration:
const InputDecoration( const InputDecoration(
hintText: 'Enter The Name', hintText:
'Enter The Name',
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: 14, fontSize: 14,
color: ColorsManager.textGray) color: ColorsManager
), .textGray)),
)), )),
], ],
), ),
Column( Column(
children: [ children: [
const Divider(color: ColorsManager.graysColor,), const Divider(
color: ColorsManager.graysColor,
),
Padding( Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [ children: [
const Expanded( const Expanded(
child: BodyMedium( child: BodyMedium(
text: 'Effective Time', text: 'Effective Time',
fontWeight: FontWeight.normal, fontWeight:
FontWeight.normal,
), ),
), ),
SizedBox( SizedBox(
width: MediaQuery.of(context).size.width / 3.5, width:
MediaQuery.of(context)
.size
.width /
3.5,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
BlocProvider.of<SmartDoorBloc>(context).add(SelectTimeEvent(context: context, isEffective: true)); BlocProvider.of<
SmartDoorBloc>(
context)
.add(
SelectTimeEvent(
context:
context,
isEffective:
true));
}, },
child: Text( child: Text(
BlocProvider.of<SmartDoorBloc>(context).effectiveTime, BlocProvider.of<SmartDoorBloc>(
context)
.effectiveTime ==
'Select Time'
? cleaned.toString()
: BlocProvider.of<
SmartDoorBloc>(
context)
.effectiveTime,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: BlocProvider.of<SmartDoorBloc>(context).effectiveTime ==
'Select Time' ? ColorsManager.textGray : null),
), ),
)),], ),
)),
],
), ),
), ),
const Divider( const Divider(
@ -196,30 +242,48 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
), ),
Padding( Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Row(mainAxisAlignment: child: Row(
MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [ children: [
const Expanded( const Expanded(
child: BodyMedium( child: BodyMedium(
text: 'Expiration Time', text: 'Expiration Time',
fontWeight: FontWeight.normal, fontWeight:
FontWeight.normal,
), ),
), ),
SizedBox( SizedBox(
width: MediaQuery.of(context).size.width / 3.5, width: MediaQuery.of(context)
.size
.width /
3.5,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
BlocProvider.of<SmartDoorBloc>(context).add(SelectTimeEvent( BlocProvider.of<
SmartDoorBloc>(
context)
.add(SelectTimeEvent(
context: context, context: context,
isEffective: false)); isEffective:
false));
}, },
child: Text( child: Text(
BlocProvider.of<SmartDoorBloc>(context).expirationTime, BlocProvider.of<
SmartDoorBloc>(
context)
.expirationTime,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: BlocProvider.of<SmartDoorBloc>(context) color: BlocProvider.of<
.expirationTime == 'Select Time' ? ColorsManager SmartDoorBloc>(
.textGray : null), context)
.expirationTime ==
'Select Time'
? ColorsManager
.textGray
: null),
), ),
), ),
), ),
@ -238,7 +302,8 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
), ),
const BodyMedium( const BodyMedium(
textAlign: TextAlign.center, textAlign: TextAlign.center,
text: 'Use the time-limited password at least once within 24 hours after the password takes effect. Otherwise, the password becomes invalid.', text:
'Use the time-limited password at least once within 24 hours after the password takes effect. Otherwise, the password becomes invalid.',
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
fontColor: ColorsManager.grayColor, fontColor: ColorsManager.grayColor,
), ),
@ -256,9 +321,12 @@ class CreateOfflineTimeLimitPasswordPage extends StatelessWidget {
backgroundColor: ColorsManager.primaryColor, backgroundColor: ColorsManager.primaryColor,
onPressed: () async { onPressed: () async {
if (generated == false) { if (generated == false) {
smartDoorBloc.add(GenerateAndSavePasswordTimeLimitEvent(context: context)); smartDoorBloc.add(
GenerateAndSavePasswordTimeLimitEvent(
context: context));
} else { } else {
if(smartDoorBloc.passwordNameController.text.isNotEmpty){ if (smartDoorBloc
.passwordNameController.text.isNotEmpty) {
smartDoorBloc.add(RenamePasswordEvent()); smartDoorBloc.add(RenamePasswordEvent());
} }
Navigator.of(context).pop(true); Navigator.of(context).pop(true);