felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
389 stars 63 forks source link

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

Open arnoldmitrica opened 5 months ago

arnoldmitrica commented 5 months ago

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 commented 3 months ago

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

arnoldmitrica commented 3 months ago

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 commented 2 months ago

@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!