Skip to content

Instantly share code, notes, and snippets.

@iapicca
Last active December 22, 2024 16:33
Show Gist options
  • Save iapicca/08dc2bd1d210e163b561399d1974ba84 to your computer and use it in GitHub Desktop.
Save iapicca/08dc2bd1d210e163b561399d1974ba84 to your computer and use it in GitHub Desktop.
issue_160724
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
final _router = GoRouter(
routes: [
GoRoute(
path: '/',
pageBuilder: (context, state) => MaterialPage(
key: state.pageKey,
child: const HomeScreen(),
),
routes: [
GoRoute(
path: 'details',
pageBuilder: (context, state) => MaterialPage(
key: state.pageKey,
child: const DetailsScreen(),
),
),
],
),
],
);
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(context) => MaterialApp.router(routerConfig: _router);
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(context) {
print('building HomeScreen');
return Scaffold(
appBar: AppBar(title: const Text('Home Screen')),
body: Center(
child: ElevatedButton(
onPressed: () => context.go('/details'),
child: const Text('Go to the Details screen'),
),
),
);
}
}
class DetailsScreen extends StatelessWidget {
const DetailsScreen({super.key});
@override
Widget build(context) {
print('building DetailsScreen');
return Scaffold(
appBar: AppBar(title: const Text('Details Screen')),
body: Center(
child: ElevatedButton(
onPressed: () => context.go('/'),
child: const Text('Go back to the Home screen'),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment