12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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'),
- ),
- ],
- ),
- ),
- );
- }
- }
|