Skip to content

Commit

Permalink
Fix autofocus for Sharecode textfield
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreichardt committed Apr 30, 2024
1 parent 3be4057 commit a1802e8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/lib/groups/group_join/widgets/group_join_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _GroupJoinTextFieldState extends State<GroupJoinTextField> {
void initState() {
super.initState();
if (!PlatformCheck.isWeb) {
copySharecodeFromClipboardOrOpenKeyboard();
copySharecodeFromClipboardOrOpenKeyboard(sharecodeFieldFocusNode);
}
}

Expand Down Expand Up @@ -129,22 +129,23 @@ class _GroupJoinTextFieldState extends State<GroupJoinTextField> {
);
}

void copySharecodeFromClipboardOrOpenKeyboard() {
void copySharecodeFromClipboardOrOpenKeyboard(FocusNode focusNode) {
final bloc = BlocProvider.of<GroupJoinBloc>(context);
bloc.getSharecodeFromClipboard().then((sharecode) {
if (sharecode == null) {
_openKeyboardForSharecodeField();
_openKeyboardForSharecodeField(focusNode);
} else {
showCopySharecodeFromClipboardDialog(sharecode);
showCopySharecodeFromClipboardDialog(sharecode, focusNode);
}
});
}

void _openKeyboardForSharecodeField() {
FocusManager.instance.primaryFocus?.unfocus();
void _openKeyboardForSharecodeField(FocusNode focusNode) {
FocusManager.instance.primaryFocus?.requestFocus(focusNode);
}

Future<void> showCopySharecodeFromClipboardDialog(Sharecode sharecode) async {
Future<void> showCopySharecodeFromClipboardDialog(
Sharecode sharecode, FocusNode focusNode) async {
final bloc = BlocProvider.of<GroupJoinBloc>(context);

final result = await showLeftRightAdaptiveDialog<bool>(
Expand Down Expand Up @@ -174,7 +175,7 @@ class _GroupJoinTextFieldState extends State<GroupJoinTextField> {
final groupJoinResultDialog = GroupJoinResultDialog(bloc);
groupJoinResultDialog.show(context);
} else {
_openKeyboardForSharecodeField();
_openKeyboardForSharecodeField(focusNode);
}
}

Expand Down

0 comments on commit a1802e8

Please sign in to comment.