Skip to content

Commit b111320

Browse files
authored
Merge pull request #72 from PDG-NUTRI/68-ajouter-la-bar-de-navigation
68 ajouter la bar de navigation
2 parents 5e3be08 + c71dca8 commit b111320

File tree

8 files changed

+220
-59
lines changed

8 files changed

+220
-59
lines changed

lib/router/router.dart

+24-9
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@ import 'package:auto_route/auto_route.dart';
22
import 'package:pdg_app/screens/chat.dart';
33
import 'package:pdg_app/screens/diary.dart';
44
import 'package:pdg_app/screens/login.dart';
5+
import 'package:pdg_app/screens/profile.dart';
56
import 'package:pdg_app/screens/register.dart';
67

8+
import '../screens/home.dart';
9+
710
@MaterialAutoRouter(
811
// replaceInRouteName: 'Page,Route',
912
routes: <AutoRoute>[
1013
AutoRoute(
11-
path: '/diary',
12-
page: DiaryScreen,
13-
initial: true,
14-
children: [],
15-
),
16-
AutoRoute(
17-
page: ChatScreen,
18-
path: '/chat',
14+
path: '/home',
15+
page: HomeScreen,
1916
initial: true,
17+
children: [
18+
RedirectRoute(
19+
path: '',
20+
redirectTo: 'diary',
21+
),
22+
AutoRoute(
23+
page: ChatScreen,
24+
path: 'chat',
25+
),
26+
AutoRoute(
27+
page: DiaryScreen,
28+
path: 'diary',
29+
),
30+
AutoRoute(
31+
page: ProfileScreen,
32+
path: 'my',
33+
)
34+
],
2035
),
2136
AutoRoute(
2237
page: LoginScreen,
@@ -28,7 +43,7 @@ import 'package:pdg_app/screens/register.dart';
2843
),
2944
RedirectRoute(
3045
path: '*',
31-
redirectTo: '/diary',
46+
redirectTo: '/home/diary',
3247
),
3348
],
3449
)

lib/router/router.gr.dart

+83-45
Original file line numberDiff line numberDiff line change
@@ -11,80 +11,118 @@
1111
// ignore_for_file: type=lint
1212

1313
// ignore_for_file: no_leading_underscores_for_library_prefixes
14-
import 'package:auto_route/auto_route.dart' as _i5;
15-
import 'package:flutter/material.dart' as _i6;
14+
import 'package:auto_route/auto_route.dart' as _i7;
15+
import 'package:flutter/material.dart' as _i8;
1616

17-
import '../screens/chat.dart' as _i2;
18-
import '../screens/diary.dart' as _i1;
19-
import '../screens/login.dart' as _i3;
20-
import '../screens/register.dart' as _i4;
17+
import '../screens/chat.dart' as _i4;
18+
import '../screens/diary.dart' as _i5;
19+
import '../screens/home.dart' as _i1;
20+
import '../screens/login.dart' as _i2;
21+
import '../screens/profile.dart' as _i6;
22+
import '../screens/register.dart' as _i3;
2123

22-
class AppRouter extends _i5.RootStackRouter {
23-
AppRouter([_i6.GlobalKey<_i6.NavigatorState>? navigatorKey])
24+
class AppRouter extends _i7.RootStackRouter {
25+
AppRouter([_i8.GlobalKey<_i8.NavigatorState>? navigatorKey])
2426
: super(navigatorKey);
2527

2628
@override
27-
final Map<String, _i5.PageFactory> pagesMap = {
28-
DiaryScreenRoute.name: (routeData) {
29-
return _i5.MaterialPageX<dynamic>(
30-
routeData: routeData, child: const _i1.DiaryScreen());
31-
},
32-
ChatScreenRoute.name: (routeData) {
33-
return _i5.MaterialPageX<dynamic>(
34-
routeData: routeData, child: const _i2.ChatScreen());
29+
final Map<String, _i7.PageFactory> pagesMap = {
30+
HomeScreenRoute.name: (routeData) {
31+
return _i7.MaterialPageX<dynamic>(
32+
routeData: routeData, child: const _i1.HomeScreen());
3533
},
3634
LoginScreenRoute.name: (routeData) {
37-
return _i5.MaterialPageX<dynamic>(
38-
routeData: routeData, child: const _i3.LoginScreen());
35+
return _i7.MaterialPageX<dynamic>(
36+
routeData: routeData, child: const _i2.LoginScreen());
3937
},
4038
RegisterScreenRoute.name: (routeData) {
41-
return _i5.MaterialPageX<dynamic>(
42-
routeData: routeData, child: const _i4.RegisterScreen());
39+
return _i7.MaterialPageX<dynamic>(
40+
routeData: routeData, child: const _i3.RegisterScreen());
41+
},
42+
ChatScreenRoute.name: (routeData) {
43+
return _i7.MaterialPageX<dynamic>(
44+
routeData: routeData, child: const _i4.ChatScreen());
45+
},
46+
DiaryScreenRoute.name: (routeData) {
47+
return _i7.MaterialPageX<dynamic>(
48+
routeData: routeData, child: const _i5.DiaryScreen());
49+
},
50+
ProfileScreenRoute.name: (routeData) {
51+
return _i7.MaterialPageX<dynamic>(
52+
routeData: routeData, child: const _i6.ProfileScreen());
4353
}
4454
};
4555

4656
@override
47-
List<_i5.RouteConfig> get routes => [
48-
_i5.RouteConfig('/#redirect',
49-
path: '/', redirectTo: '/diary', fullMatch: true),
50-
_i5.RouteConfig(DiaryScreenRoute.name, path: '/diary'),
51-
_i5.RouteConfig(ChatScreenRoute.name, path: '/chat'),
52-
_i5.RouteConfig(LoginScreenRoute.name, path: '/login'),
53-
_i5.RouteConfig(RegisterScreenRoute.name, path: '/register'),
54-
_i5.RouteConfig('*#redirect',
55-
path: '*', redirectTo: '/diary', fullMatch: true)
57+
List<_i7.RouteConfig> get routes => [
58+
_i7.RouteConfig('/#redirect',
59+
path: '/', redirectTo: '/home', fullMatch: true),
60+
_i7.RouteConfig(HomeScreenRoute.name, path: '/home', children: [
61+
_i7.RouteConfig('#redirect',
62+
path: '',
63+
parent: HomeScreenRoute.name,
64+
redirectTo: 'diary',
65+
fullMatch: true),
66+
_i7.RouteConfig(ChatScreenRoute.name,
67+
path: 'chat', parent: HomeScreenRoute.name),
68+
_i7.RouteConfig(DiaryScreenRoute.name,
69+
path: 'diary', parent: HomeScreenRoute.name),
70+
_i7.RouteConfig(ProfileScreenRoute.name,
71+
path: 'my', parent: HomeScreenRoute.name)
72+
]),
73+
_i7.RouteConfig(LoginScreenRoute.name, path: '/login'),
74+
_i7.RouteConfig(RegisterScreenRoute.name, path: '/register'),
75+
_i7.RouteConfig('*#redirect',
76+
path: '*', redirectTo: '/home/diary', fullMatch: true)
5677
];
5778
}
5879

5980
/// generated route for
60-
/// [_i1.DiaryScreen]
61-
class DiaryScreenRoute extends _i5.PageRouteInfo<void> {
62-
const DiaryScreenRoute() : super(DiaryScreenRoute.name, path: '/diary');
63-
64-
static const String name = 'DiaryScreenRoute';
65-
}
81+
/// [_i1.HomeScreen]
82+
class HomeScreenRoute extends _i7.PageRouteInfo<void> {
83+
const HomeScreenRoute({List<_i7.PageRouteInfo>? children})
84+
: super(HomeScreenRoute.name, path: '/home', initialChildren: children);
6685

67-
/// generated route for
68-
/// [_i2.ChatScreen]
69-
class ChatScreenRoute extends _i5.PageRouteInfo<void> {
70-
const ChatScreenRoute() : super(ChatScreenRoute.name, path: '/chat');
71-
72-
static const String name = 'ChatScreenRoute';
86+
static const String name = 'HomeScreenRoute';
7387
}
7488

7589
/// generated route for
76-
/// [_i3.LoginScreen]
77-
class LoginScreenRoute extends _i5.PageRouteInfo<void> {
90+
/// [_i2.LoginScreen]
91+
class LoginScreenRoute extends _i7.PageRouteInfo<void> {
7892
const LoginScreenRoute() : super(LoginScreenRoute.name, path: '/login');
7993

8094
static const String name = 'LoginScreenRoute';
8195
}
8296

8397
/// generated route for
84-
/// [_i4.RegisterScreen]
85-
class RegisterScreenRoute extends _i5.PageRouteInfo<void> {
98+
/// [_i3.RegisterScreen]
99+
class RegisterScreenRoute extends _i7.PageRouteInfo<void> {
86100
const RegisterScreenRoute()
87101
: super(RegisterScreenRoute.name, path: '/register');
88102

89103
static const String name = 'RegisterScreenRoute';
90104
}
105+
106+
/// generated route for
107+
/// [_i4.ChatScreen]
108+
class ChatScreenRoute extends _i7.PageRouteInfo<void> {
109+
const ChatScreenRoute() : super(ChatScreenRoute.name, path: 'chat');
110+
111+
static const String name = 'ChatScreenRoute';
112+
}
113+
114+
/// generated route for
115+
/// [_i5.DiaryScreen]
116+
class DiaryScreenRoute extends _i7.PageRouteInfo<void> {
117+
const DiaryScreenRoute() : super(DiaryScreenRoute.name, path: 'diary');
118+
119+
static const String name = 'DiaryScreenRoute';
120+
}
121+
122+
/// generated route for
123+
/// [_i6.ProfileScreen]
124+
class ProfileScreenRoute extends _i7.PageRouteInfo<void> {
125+
const ProfileScreenRoute() : super(ProfileScreenRoute.name, path: 'my');
126+
127+
static const String name = 'ProfileScreenRoute';
128+
}

lib/screens/home.dart

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:auto_route/auto_route.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:pdg_app/router/router.gr.dart';
4+
5+
import '../widgets/navbar.dart';
6+
7+
class HomeScreen extends StatefulWidget {
8+
const HomeScreen({Key? key}) : super(key: key);
9+
10+
@override
11+
State<HomeScreen> createState() => _HomeScreenState();
12+
}
13+
14+
class _HomeScreenState extends State<HomeScreen> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return AutoTabsRouter(
18+
routes: const [
19+
ChatScreenRoute(),
20+
DiaryScreenRoute(),
21+
ProfileScreenRoute(),
22+
],
23+
builder: (context, child, animation) {
24+
return Scaffold(
25+
body: FadeTransition(
26+
opacity: animation,
27+
child: child,
28+
),
29+
bottomNavigationBar: const NavBar(),
30+
);
31+
},
32+
);
33+
}
34+
}

lib/screens/profile.dart

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ProfileScreen extends StatelessWidget {
4+
const ProfileScreen({Key? key}) : super(key: key);
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return const Center(child: Text("Profile"));
9+
}
10+
}

lib/widgets/navbar.dart

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:auto_route/auto_route.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:google_nav_bar/google_nav_bar.dart';
4+
5+
class NavBar extends StatefulWidget {
6+
const NavBar({Key? key}) : super(key: key);
7+
8+
@override
9+
State<NavBar> createState() => _NavBarState();
10+
}
11+
12+
class _NavBarState extends State<NavBar> {
13+
int _selectedIndex = 1;
14+
15+
@override
16+
Widget build(BuildContext context) {
17+
final tabsRouter = AutoTabsRouter.of(context);
18+
19+
return GNav(
20+
rippleColor: Theme.of(context).colorScheme.secondary,
21+
hoverColor: Theme.of(context).colorScheme.secondary,
22+
color: Theme.of(context).colorScheme.onSecondary,
23+
activeColor: Theme.of(context).colorScheme.onSecondary,
24+
duration: const Duration(milliseconds: 900),
25+
tabBackgroundColor: Theme.of(context).colorScheme.secondary,
26+
gap: 8,
27+
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 15),
28+
tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 25),
29+
backgroundColor: Theme.of(context).colorScheme.surface,
30+
tabs: const [
31+
GButton(
32+
icon: Icons.chat_bubble_outline,
33+
text: "Chat",
34+
),
35+
GButton(
36+
icon: Icons.calendar_month_outlined,
37+
text: "Diary",
38+
),
39+
GButton(
40+
icon: Icons.account_circle_outlined,
41+
text: "Profile",
42+
)
43+
],
44+
selectedIndex: _selectedIndex,
45+
onTabChange: (index) {
46+
setState(() {
47+
_selectedIndex = index;
48+
tabsRouter.setActiveIndex(index);
49+
});
50+
},
51+
);
52+
}
53+
}

pubspec.lock

+7
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ packages:
422422
url: "https://pub.dartlang.org"
423423
source: hosted
424424
version: "3.1.1"
425+
google_nav_bar:
426+
dependency: "direct main"
427+
description:
428+
name: google_nav_bar
429+
url: "https://pub.dartlang.org"
430+
source: hosted
431+
version: "5.0.6"
425432
graphs:
426433
dependency: transitive
427434
description:

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies:
4444
table_calendar: ^3.0.6
4545
intl: ^0.17.0
4646
uuid: ^3.0.6
47+
google_nav_bar: ^5.0.6
4748

4849
dev_dependencies:
4950
flutter_test:

widgetbook/widgetbook.dart

+8-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,14 @@ class HotReload extends StatelessWidget {
113113
],
114114
);
115115

116-
var actionButton = WidgetbookComponent(name: 'Action button', useCases: [
117-
WidgetbookUseCase(
118-
name: 'Add',
119-
builder: (context) => const ActionButton(icon: Icons.add))
120-
]);
116+
var actionButton = WidgetbookComponent(
117+
name: 'Action button',
118+
useCases: [
119+
WidgetbookUseCase(
120+
name: 'Add',
121+
builder: (context) => const ActionButton(icon: Icons.add))
122+
],
123+
);
121124

122125
var login = WidgetbookComponent(
123126
name: 'Login',

0 commit comments

Comments
 (0)