forked from Milad-Akarie/auto_route_library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chores: add nested navigation example chores: add declarative navigation example
- Loading branch information
1 parent
211e963
commit d3ff303
Showing
6 changed files
with
185 additions
and
26 deletions.
There are no files selected for viewing
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
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
80 changes: 80 additions & 0 deletions
80
auto_route/example/lib/nested-navigation/nested_navigation.router.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:example/nested-navigation/nested_navigation.router.gr.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(NestedNavigationApp()); | ||
} | ||
|
||
class NestedNavigationApp extends StatelessWidget { | ||
NestedNavigationApp({super.key}); | ||
|
||
final nestedRouter = NestedRouter(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp.router( | ||
routerConfig: nestedRouter.config(), | ||
); | ||
} | ||
} | ||
|
||
@AutoRouterConfig(generateForDir: ['lib/nested-navigation']) | ||
class NestedRouter extends RootStackRouter { | ||
@override | ||
List<AutoRoute> get routes => [ | ||
AutoRoute( | ||
initial: true, | ||
page: HostRoute.page, | ||
children: [ | ||
AutoRoute(page: FirstRoute.page, initial: true), | ||
AutoRoute(page: SecondRoute.page), | ||
], | ||
), | ||
]; | ||
} | ||
|
||
@RoutePage() | ||
class HostScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Host Screen'), | ||
/// This will automatically display a back button if the nested router can pop | ||
leading: AutoLeadingButton(), | ||
), | ||
body: AutoRouter(), | ||
); | ||
} | ||
} | ||
|
||
@RoutePage() | ||
class FirstScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: ElevatedButton( | ||
onPressed: () => context.pushRoute(SecondRoute()), | ||
child: Text('Go to second screen'), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
@RoutePage() | ||
class SecondScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: ElevatedButton( | ||
onPressed: () => context.maybePop(), | ||
child: Text('Go Back'), | ||
), | ||
), | ||
); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
auto_route/example/lib/nested-navigation/nested_navigation.router.gr.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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