Skip to content

Instantly share code, notes, and snippets.

@bizz84
Created June 23, 2024 20:07
Show Gist options
  • Save bizz84/986a1039331f699c5261f22638e4ad93 to your computer and use it in GitHub Desktop.
Save bizz84/986a1039331f699c5261f22638e4ad93 to your computer and use it in GitHub Desktop.
Simple GoRouter navigation to a details page
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