Flutter Landing Page To Navigate User Depends On A State
How can I navigate the user to the relevant screen? For example, If the user signed in, then the user must go homepage, but the user did not sign in, so the user must go login page. When I try to use navigator, then it gives this error:
FlutterError (setState() or markNeedsBuild() called during build. This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase. The widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey#3ba8a] The widget which was currently being built when the offending call was made was: BlocBuilder<AuthCubit, AuthState>)
Also, I used auto route and auto route generator, but it gives an error is: The getter 'RouteInformationReportingType' isn't defined for the class 'AutoRouteInformationProvider'. package:auto_route/…/provider/auto_route_information_provider.dart:32
Can you help me?
codes:
class LandingPage extends StatelessWidget {
const LandingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<AuthCubit, AuthState>(
builder: (context, state) {
if (state.isUserSignedIn) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const HomePage()),
);
} else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SignInPage()),
);
}
return Container();
},
),
);
}
}
Answer
I have updated flutter sdk to 2.8 and some syntax changes. That's it
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?