Short answer
Use a context from below MaterialApp. Move your home screen into its own widget (class HomePage extends StatelessWidget) and call Navigator from its build method, or wrap the button in a Builder to get a new context. To navigate from code with no context, such as a notification handler, give MaterialApp a navigatorKey and call navigatorKey.currentState.
Why the context has no Navigator, and the fix
01
The context belongs to the widget that builds MaterialApp
“If there is no Navigator in the given context, this function will throw a FlutterError in debug mode, and an exception in release mode.” Flutter, Navigator.of
MaterialApp creates the Navigator, so the build method that returns MaterialApp gets a context from above it. Split the screen into its own widget; its context sits under MaterialApp.
class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) => const MaterialApp(home: HomePage()); } class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) => Scaffold( body: TextButton( onPressed: () => Navigator.of(context).push( MaterialPageRoute(builder: (_) => const DetailsPage()), // your own screen widget ), child: const Text('Open'), ), ); }02
A quick fix inside the same build method
“This widget is an inline alternative to defining a StatelessWidget subclass.” Flutter, Builder class
If you’d rather not split the widget, wrap the part that navigates in a Builder. Its builder callback gets a new context below MaterialApp.
MaterialApp( home: Builder( builder: (context) => TextButton( onPressed: () => Navigator.of(context).push( MaterialPageRoute(builder: (_) => const DetailsPage()), ), child: const Text('Open'), ), ), )03
Navigating from code that has no widget context
“If a navigatorKey is specified, the Navigator can be directly manipulated without first obtaining it from a BuildContext via Navigator.of” Flutter, MaterialApp.navigatorKey
Push notification taps, auth state listeners and services don’t have a context under MaterialApp. Give MaterialApp a GlobalKey<NavigatorState> and navigate through it.
final navigatorKey = GlobalKey<NavigatorState>(); void main() { runApp(MaterialApp(navigatorKey: navigatorKey, home: const HomePage())); } // anywhere, after the first frame (InboxPage is your own screen widget) void openInbox() { navigatorKey.currentState?.push( MaterialPageRoute(builder: (_) => const InboxPage()), ); }
Checked against the vendor’s docs on : Flutter API: Navigator.of; Flutter API: Builder class; Flutter API: MaterialApp.navigatorKey.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Flutter “Scaffold.of() called with a context” · Flutter “deactivated widget’s ancestor” · Flutter setState() called during build · Flutter “type 'Null' is not a subtype of type 'String'”