Skip to content

Commit

Permalink
Fixed the text field hang issue on lock and unlock the device. (#197)
Browse files Browse the repository at this point in the history
* Fixed the checkbox issue for gender selection when UI spec set to checkbox

Signed-off-by: G S Prakash <[email protected]>

* Fixed the textformfield issue while lock and unlocked

Signed-off-by: G S Prakash <[email protected]>

---------

Signed-off-by: G S Prakash <[email protected]>
  • Loading branch information
GSPrakash2662 authored Nov 14, 2023
1 parent 9a43da5 commit ce7618d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/ui/process_ui/widgets/textbox_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:responsive_grid_list/responsive_grid_list.dart';
import '../../../model/field.dart';

import '../../../provider/global_provider.dart';
import '../../../utils/life_cycle_event_handler.dart';
import 'custom_label.dart';

class TextBoxControl extends StatefulWidget {
Expand All @@ -21,12 +22,39 @@ class TextBoxControl extends StatefulWidget {
State<TextBoxControl> createState() => _TextBoxControlState();
}

class _TextBoxControlState extends State<TextBoxControl> {
class _TextBoxControlState extends State<TextBoxControl>
with WidgetsBindingObserver {
bool isMvelValid = true;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(LifecycleEventHandler(
resumeCallBack: () async {
if (mounted) {
setState(() {
closeKeyboard();
});
}
},
suspendingCallBack: () async {
if (mounted) {
setState(() {
closeKeyboard();
});
}
},
));
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

void closeKeyboard() {
FocusScope.of(context).unfocus();
}

void saveData(value, lang) {
Expand Down
31 changes: 31 additions & 0 deletions lib/utils/life_cycle_event_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

class LifecycleEventHandler extends WidgetsBindingObserver {
final AsyncCallback resumeCallBack;
final AsyncCallback suspendingCallBack;

LifecycleEventHandler({
required this.resumeCallBack,
required this.suspendingCallBack,
});

@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
switch (state) {
case AppLifecycleState.resumed:
if (resumeCallBack != null) {
await resumeCallBack();
}
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
case AppLifecycleState.detached:
if (suspendingCallBack != null) {
await suspendingCallBack();
}
break;
case AppLifecycleState.hidden:
}
}
}

0 comments on commit ce7618d

Please sign in to comment.