How set root view dynamically in flutter?

Issue

devs

I have a situation where I want to change my root view based on condition. For example, if a user is logged in already then root view will be Home screen else login screen.

How can I achieve this? Please help.

Thank you

Solution

in your main.dart File you have the function void main() => runApp(MyApp()); where MyApp is a widget returing a MaterialApp widget or something similar. You can already select here to start with a different home widget.

If you have to select the start screen based on some asynchronous operation (like checking settings in Preferences or Secure Storage), you return a FutureBuilder instead of your MaterialApp. The FutureBuilder then returns the widget after finishing the operation.

Answered By – Christian

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.