Created
September 18, 2022 15:24
-
-
Save iapicca/8c9af282eea7ace69b9d01ef4a9c6c9a to your computer and use it in GitHub Desktop.
issues_111831
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:go_router/go_router.dart'; | |
| void main() => runApp(const MyApp()); | |
| final _router = GoRouter( | |
| routes: <GoRoute>[ | |
| GoRoute( | |
| path: '/', | |
| builder: (context, _) => | |
| const MyHomePage(title: 'Flutter Demo Home Page'), | |
| routes: [ | |
| GoRoute( | |
| path: 'other_route', | |
| builder: (context, _) => Scaffold( | |
| appBar: AppBar(), | |
| body: const Center(child: Text('other_route')), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ], | |
| ); | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| debugPrint('building MyApp'); | |
| return MaterialApp.router( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| routeInformationProvider: _router.routeInformationProvider, | |
| routeInformationParser: _router.routeInformationParser, | |
| routerDelegate: _router.routerDelegate, | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| const MyHomePage({super.key, required this.title}); | |
| final String title; | |
| @override | |
| State<MyHomePage> createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| late final ValueNotifier<int> _counter; | |
| @override | |
| void initState() { | |
| _counter = ValueNotifier(0); | |
| super.initState(); | |
| } | |
| @override | |
| void dispose() { | |
| _counter.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(context) { | |
| debugPrint('building MyHomePage'); | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| const Text( | |
| 'You have pushed the button this many times:', | |
| ), | |
| ValueListenableBuilder<int>( | |
| valueListenable: _counter, | |
| builder: (context, counter, _) => Text( | |
| '$counter', | |
| style: Theme.of(context).textTheme.headline4, | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () { | |
| _counter.value++; | |
| context.go('/other_route'); | |
| }, | |
| tooltip: 'Increment', | |
| child: const Icon(Icons.add), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment