Skip to content

Commit efc9463

Browse files
committed
Fix: keep the focus sensitive field focused on dialog open
1 parent 456990b commit efc9463

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

modules/ensemble/lib/action/dialog_actions.dart

+15-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ShowDialogAction extends EnsembleAction {
4848

4949
@override
5050
Future execute(BuildContext context, ScopeManager scopeManager) {
51+
// Save the currently focused widget so we can keep focus on it after dialog opens
52+
FocusNode? currentFocus = FocusManager.instance.primaryFocus;
5153
// get styles. TODO: make bindable
5254
Map<String, dynamic> dialogStyles = {};
5355
options?.forEach((key, value) {
@@ -109,10 +111,21 @@ class ShowDialogAction extends EnsembleAction {
109111
useDefaultStyle ? const EdgeInsets.all(20) : null,
110112
child: DataScopeWidget(
111113
scopeManager: scopeManager.createChildScope(),
112-
child: SingleChildScrollView(
114+
child: Builder(
115+
builder: (context) {
116+
// Keep focus on the focus sensitive widgets (e.g. TextInput) after dialog opens
117+
WidgetsBinding.instance.addPostFrameCallback((_) {
118+
if (currentFocus != null && currentFocus.hasFocus) {
119+
currentFocus.requestFocus();
120+
}
121+
});
122+
return SingleChildScrollView(
113123
child: scopeManager
114124
.buildWidgetFromDefinition(body),
115-
))))));
125+
);
126+
})))),
127+
),
128+
);
116129
}).then((payload) {
117130
// remove the dialog context since we are closing them
118131
scopeManager.openedDialogs.remove(dialogContext);

0 commit comments

Comments
 (0)