The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Center(
child: MaterialButton(
child: const Text('go somewhere'),
onPressed: () => GoRouter.of(context).go('places'),
),
),
),
);
}
}
due to the implementation below
```dart
/// Find the current GoRouter in the widget tree.
static GoRouter of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<InheritedGoRouter>()!.goRouter;
To Reproduce
go_router: ^2.2.0
import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart';
void main() { runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( home: Material( child: Center( child: MaterialButton( child: const Text('go somewhere'), onPressed: () => GoRouter.of(context).go('places'), ), ), ), ); } }
in place of the canonical one
Expected behavior provide a useful error message
Actual behavior provide a vague error message