Flutter Redirect to a page on initState
Try wrapping your Navigator call: Navigator.of(context).pushNamed(“login”); in a callback that is scheduled with addPostFrameCallback: SchedulerBinding.instance.addPostFrameCallback((_) { Navigator.of(context).pushNamed(“login”); }); You’ll need this import at the top of your file: import ‘package:flutter/scheduler.dart’; As an alternative, consider if you could just have MyHomePage‘s build() method return a LoginPage instead of a Scaffold if the user isn’t logged in. … Read more