flow_builder icon indicating copy to clipboard operation
flow_builder copied to clipboard

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

Open arnoldmitrica opened this issue 1 year ago • 3 comments

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),.

arnoldmitrica avatar Jan 31 '24 20:01 arnoldmitrica

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

robsonsilv4 avatar Mar 11 '24 12:03 robsonsilv4

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<Object>( child: CustomTextFieldColumn( next: 1, ), ), if (screenIndex == 1) const MaterialPage<Object>( child: CustomTextFieldColumn( isAutofocus: true, next: 0, ), ), ]; }, ); } }

arnoldmitrica avatar Apr 02 '24 09:04 arnoldmitrica

@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 avatar Apr 20 '24 18:04 felangel