|
@@ -0,0 +1,97 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:go_router/go_router.dart';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void main() => runApp(const MyApp());
|
|
|
+
|
|
|
+
|
|
|
+final GoRouter _router = GoRouter(
|
|
|
+ routes: <RouteBase>[
|
|
|
+ GoRoute(
|
|
|
+ path: '/',
|
|
|
+ builder: (BuildContext context, GoRouterState state) {
|
|
|
+ return const HomeScreen();
|
|
|
+ },
|
|
|
+ routes: <RouteBase>[
|
|
|
+ GoRoute(
|
|
|
+ path: 'details',
|
|
|
+ builder: (BuildContext context, GoRouterState state) {
|
|
|
+ return const DetailsScreen();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
+class MyApp extends StatelessWidget {
|
|
|
+
|
|
|
+ const MyApp({Key? key}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return MaterialApp.router(
|
|
|
+ routerConfig: _router,
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+class HomeScreen extends StatelessWidget {
|
|
|
+
|
|
|
+ const HomeScreen({Key? key}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return Scaffold(
|
|
|
+ appBar: AppBar(title: const Text('Home Screen')),
|
|
|
+ body: Center(
|
|
|
+ child: Column(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: <Widget>[
|
|
|
+ ElevatedButton(
|
|
|
+ onPressed: () => context.go('/details'),
|
|
|
+ child: const Text('Go to the Details screen'),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+class DetailsScreen extends StatelessWidget {
|
|
|
+
|
|
|
+ const DetailsScreen({Key? key}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return Scaffold(
|
|
|
+ appBar: AppBar(title: const Text('Details Screen')),
|
|
|
+ body: Center(
|
|
|
+ child: Column(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: <ElevatedButton>[
|
|
|
+ ElevatedButton(
|
|
|
+ onPressed: () => context.go('/'),
|
|
|
+ child: const Text('Go back to the Home screen'),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|