Skip to content

Commit 1d55579

Browse files
committed
Finished Project
1 parent 66e1a2e commit 1d55579

File tree

10 files changed

+637
-18
lines changed

10 files changed

+637
-18
lines changed

lib/home_page.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:auto_route/auto_route.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/routes/router.gr.dart';
4+
import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';
5+
6+
class HomePage extends StatelessWidget {
7+
const HomePage({Key? key}) : super(key: key);
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return AutoTabsScaffold(
12+
appBarBuilder: (_, tabsRouter) => AppBar(
13+
backgroundColor: Colors.indigo,
14+
title: const Text('FlutterBottomNav'),
15+
centerTitle: true,
16+
leading: const AutoBackButton(),
17+
),
18+
backgroundColor: Colors.indigo,
19+
routes: const [
20+
PostsRouter(),
21+
UsersRouter(),
22+
SettingsRouter(),
23+
],
24+
bottomNavigationBuilder: (_, tabsRouter) {
25+
return SalomonBottomBar(
26+
margin: const EdgeInsets.symmetric(
27+
horizontal: 20,
28+
vertical: 40,
29+
),
30+
currentIndex: tabsRouter.activeIndex,
31+
onTap: tabsRouter.setActiveIndex,
32+
items: [
33+
SalomonBottomBarItem(
34+
selectedColor: Colors.amberAccent,
35+
icon: const Icon(
36+
Icons.post_add,
37+
size: 30,
38+
),
39+
title: const Text('Posts'),
40+
),
41+
SalomonBottomBarItem(
42+
selectedColor: Colors.blue[200],
43+
icon: const Icon(
44+
Icons.person,
45+
size: 30,
46+
),
47+
title: const Text('Users'),
48+
),
49+
SalomonBottomBarItem(
50+
selectedColor: Colors.pinkAccent[100],
51+
icon: const Icon(
52+
Icons.settings,
53+
size: 30,
54+
),
55+
title: const Text('Settings'),
56+
)
57+
],
58+
);
59+
},
60+
);
61+
}
62+
}

lib/main.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/posts/posts_page.dart';
2+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/routes/router.gr.dart';
33

44
void main() => runApp(const AppWidget());
55

@@ -8,10 +8,12 @@ class AppWidget extends StatelessWidget {
88

99
@override
1010
Widget build(BuildContext context) {
11-
return MaterialApp(
11+
final _appRouter = AppRouter();
12+
return MaterialApp.router(
1213
debugShowCheckedModeBanner: false,
1314
title: 'Bottom Nav Bar with Nested Routing',
14-
home: PostsPage(),
15+
routerDelegate: _appRouter.delegate(),
16+
routeInformationParser: _appRouter.defaultRouteParser(),
1517
);
1618
}
1719
}

lib/posts/posts_page.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'package:flutter/material.dart';
2+
import 'package:auto_route/auto_route.dart';
23
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/data/app_data.dart';
4+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/routes/router.gr.dart';
35
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/widgets.dart';
46

5-
67
class PostsPage extends StatelessWidget {
78
PostsPage({Key? key}) : super(key: key);
89
final posts = Post.posts;
@@ -13,17 +14,21 @@ class PostsPage extends StatelessWidget {
1314
padding: const EdgeInsets.symmetric(
1415
horizontal: 20,
1516
),
16-
child: Column(
17-
mainAxisAlignment: MainAxisAlignment.center,
18-
children: [
19-
for (int i = 0; i < posts.length; i++)
20-
PostTile(
21-
tileColor: posts[i].color,
22-
postTitle: posts[i].title,
23-
onTileTap: (){},
24-
),
25-
],
26-
),
17+
child: Column(
18+
mainAxisAlignment: MainAxisAlignment.center,
19+
children: [
20+
for (int i = 0; i < posts.length; i++)
21+
PostTile(
22+
tileColor: posts[i].color,
23+
postTitle: posts[i].title,
24+
onTileTap: () => context.router.push(
25+
SinglePostRoute(
26+
postId: posts[i].id,
27+
),
28+
),
29+
),
30+
],
31+
),
2732
),
2833
);
2934
}

lib/posts/single_post_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import 'package:auto_route/annotations.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/data/app_data.dart';
34

45
class SinglePostPage extends StatelessWidget {
56
final int postId;
67
const SinglePostPage({
78
Key? key,
8-
required this.postId,
9+
@PathParam() required this.postId,
910
}) : super(key: key);
1011

1112
@override

lib/routes/router.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:auto_route/auto_route.dart';
2+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/home_page.dart';
3+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/posts/posts_page.dart';
4+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/posts/single_post_page.dart';
5+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/settings/settings_page.dart';
6+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/users/user_profile_page.dart';
7+
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/users/users_page.dart';
8+
9+
@MaterialAutoRouter(
10+
replaceInRouteName: 'Page,Route',
11+
routes: [
12+
AutoRoute(path: '/', page: HomePage, children: [
13+
AutoRoute(
14+
path: 'posts',
15+
name: 'PostsRouter',
16+
page: EmptyRouterPage,
17+
children: [
18+
AutoRoute(
19+
path: '',
20+
page: PostsPage,
21+
),
22+
AutoRoute(
23+
path: ':postId',
24+
page: SinglePostPage,
25+
)
26+
],
27+
),
28+
AutoRoute(
29+
path: 'users',
30+
name: 'UsersRouter',
31+
page: EmptyRouterPage,
32+
children: [
33+
AutoRoute(
34+
path: '',
35+
page: UsersPage,
36+
),
37+
AutoRoute(
38+
path: ':userId',
39+
page: UserProfilePage,
40+
),
41+
],
42+
),
43+
AutoRoute(
44+
path: 'settings',
45+
name: 'SettingsRouter',
46+
page: SettingsPage,
47+
)
48+
]),
49+
],
50+
)
51+
class $AppRouter {}

lib/routes/router.gr.dart

Lines changed: 171 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/users/user_profile_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:auto_route/annotations.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/data/app_data.dart';
34
import 'package:flutter_bottom_navigation_with_nested_routing_tutorial/widgets.dart';
@@ -6,7 +7,7 @@ class UserProfilePage extends StatelessWidget {
67
final int userId;
78
const UserProfilePage({
89
Key? key,
9-
required this.userId,
10+
@PathParam() required this.userId,
1011
}) : super(key: key);
1112

1213
@override

0 commit comments

Comments
 (0)