Created
June 23, 2024 20:07
-
-
Save bizz84/986a1039331f699c5261f22638e4ad93 to your computer and use it in GitHub Desktop.
Simple GoRouter navigation to a details page
This file contains 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'; | |
final _router = GoRouter( | |
routes: [ | |
GoRoute( | |
path: '/', | |
builder: (context, state) => const HomeScreen(), | |
routes: [ | |
GoRoute( | |
path: 'details', | |
builder: (context, state) => const HomeScreen(), | |
), | |
], | |
), | |
], | |
); | |
void main() { | |
runApp(const MainApp()); | |
} | |
class MainApp extends StatelessWidget { | |
const MainApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp.router( | |
routerConfig: _router, | |
); | |
} | |
} | |
class HomeScreen extends StatelessWidget { | |
const HomeScreen({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: ElevatedButton( | |
onPressed: () => context.go('/details'), | |
child: const Text('go'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment