Skip to content

Instantly share code, notes, and snippets.

@pedromassango
Created June 18, 2021 06:56
Show Gist options
  • Save pedromassango/18d6e2c4b741a03849c99ccd113a401d to your computer and use it in GitHub Desktop.
Save pedromassango/18d6e2c4b741a03849c99ccd113a401d to your computer and use it in GitHub Desktop.
/// The main screen launched with Navigator.push(...)
/// the question is where do I load the data of the EmailPage, without making it a StatefulWidget?
/// I guess we can solve that by adding a callback on the BlocBuilder widget.
class RegistrationFlow extends StatelessWidget {
const RegistrationFlow({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
Provider(create: (_) => UsernameBloc()),
Provider(create: (_) => EmailBloc()),
],
child: Scaffold(
body: PageView(
children: [
UsernamePage(),
EmailPage(),
// More pages...
],
),
),
);
}
}
class UsernamePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<UsernameBloc, UsernameState>(
builder: (context, state) {
return Container();
},
);
}
}
class EmailPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<EmailBloc, EmailState>(
builder: (context, state) {
return Container();
},
);
}
}
@pedromassango
Copy link
Author

Thanks for checking out. I forgot to mention that, once the flow is complete, I would need to get everything for each "Page" bloc/state and send it to the server from the RegistrationFlow widget (which has a eventual "RegistrationBloc").

With your suggestion above I won't be able to get the inner Blocs to retrieve its data. Please let me know if there I still a better way to do that :)

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment