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

Clarification needed on automatic routing on state change #111

Open Lewynation opened 11 months ago

Lewynation commented 11 months ago

I am using flutter bloc for state management and flow builder for routing, just like it has been used in the flutter news toolkit provided by the flutter team. I expect routing to be handled automatically by flow builder once state changes, however that is not the case in my scenario. Below are code snippets of my setup. What could i be doing wrong?

The Flowbuilder widget:

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: AppTheme().themeData,
      darkTheme: AppDarkTheme().themeData,
      themeMode: ThemeMode.system,
      debugShowCheckedModeBanner: false,
      home: AuthenticatedUserListener(
        child: FlowBuilder<AppStatus>(
          state: context.watch<AppBloc>().state.status,
          onGeneratePages: onGenerateAppViewPages,
        ),
      ),
    );
  }
}

Then the ongenerate pages function:

List<Page<dynamic>> onGenerateAppViewPages(
  AppStatus state,
  List<Page<dynamic>> pages,
) {
  print("Appstate changed");
  switch (state) {
    case AppStatus.onboardingRequired:
      return [OnboardingPage.page()];
    case AppStatus.unauthenticated:
      return [LoginPage.page()];
    case AppStatus.authenticated:
      print("OBJECT: HOME PAGE");
      return [HomePage.page()];
    case AppStatus.maintenanceOngoing:
      return [MaintenanceOngoingPage.page()];
    case AppStatus.updateRequired:
      return [UpdateRequiredPage.page()];
    case AppStatus.userPhoneVerificationRequired:
      print("OBJECT: PHONE AUTH PAGE");
      return [ExtraUserDetailsRequiredPage.page()];
  }
}

Upon state change, the print statements are being called, however there is no route change, any information is welcome.