Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextFormField's autofocus from a second MaterialPages is not working. #119

Open
arnoldmitrica opened this issue Jan 31, 2024 · 3 comments
Open
Labels
question Further information is requested waiting for response Waiting for additional information

Comments

@arnoldmitrica
Copy link

Describe the bug
Once the first textformfield gets focused then the next one from the second MaterialPage is not getting autofocused.

To Reproduce
Let's say for example we have 2 MaterialPages:
[
MaterialPage(child: FirstColumnTextField()),
MaterialPage(child: SecondColumnTextField(autofocus: true)),
]
Expected behavior
Second textfield gets autofocused as the TextFormField is set. The only fix for now is to set the maintainState to false to the first MaterialPage as follows: MaterialPage(child: FirstColumnTextField(), maintainState: false),.

@robsonsilv4
Copy link

Hi @arnoldmitrica, can you share a minimal example project to reproduce this issue?

@arnoldmitrica
Copy link
Author

class CustomTextFieldColumn extends StatelessWidget {
final int next;
final bool isAutofocus;

const CustomTextFieldColumn(
{required this.next, this.isAutofocus = false, super.key});

@OverRide
Widget build(BuildContext context) {
return Column(
children: [
TextFormField(autofocus: isAutofocus),
ElevatedButton(
onPressed: () => context.flow().update((state) => next),
child: Text('Next screen')),
],
);
}
}

class PageFlow extends StatelessWidget {
const PageFlow({super.key});

@OverRide
Widget build(BuildContext context) {
return FlowBuilder(
onGeneratePages: (screenIndex, e) {
return [
if (screenIndex == 0)
const MaterialPage(
child: CustomTextFieldColumn(
next: 1,
),
),
if (screenIndex == 1)
const MaterialPage(
child: CustomTextFieldColumn(
isAutofocus: true,
next: 0,
),
),
];
},
);
}
}

@felangel
Copy link
Owner

@arnoldmitrica the code you shared isn't a minimal reproduction sample because we can't run it. Can you please share a complete, runnable main.dart or a link to a GitHub repo so we can easily reproduce the issue locally? Thanks!

@felangel felangel added question Further information is requested waiting for response Waiting for additional information labels Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting for response Waiting for additional information
Projects
None yet
Development

No branches or pull requests

3 participants