From 7f921e0838745f34d8abd771aecd84a8e0386d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Mon, 29 Aug 2022 14:15:03 +0200 Subject: [PATCH 1/7] Add depedency --- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 2 files changed, 8 insertions(+) diff --git a/pubspec.lock b/pubspec.lock index 199b6f3..295984a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -415,6 +415,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.1" + google_nav_bar: + dependency: "direct main" + description: + name: google_nav_bar + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.6" graphs: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 761392c..8c83b7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: provider: ^6.0.3 flutter_chat_ui: ^1.6.4 uuid: ^3.0.6 + google_nav_bar: ^5.0.6 dev_dependencies: flutter_test: From f2fd1be1c39d65c05b09a15a570dad4eed73d77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Mon, 29 Aug 2022 14:53:43 +0200 Subject: [PATCH 2/7] WIP --- lib/router/router.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/router/router.dart b/lib/router/router.dart index 14923f2..78bde4d 100644 --- a/lib/router/router.dart +++ b/lib/router/router.dart @@ -10,12 +10,14 @@ import 'package:pdg_app/screens/register.dart'; AutoRoute( path: '/home', page: HomeScreen, - children: [], - ), - AutoRoute( - page: ChatScreen, - path: '/chat', initial: true, + children: [ + AutoRoute( + page: ChatScreen, + path: '/chat', + initial: true, + ), + ], ), AutoRoute( page: LoginScreen, From 6c89aad92e9cdec3d71099e91b4f36ce19591fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Mon, 29 Aug 2022 15:40:07 +0200 Subject: [PATCH 3/7] Nested routes --- lib/router/router.dart | 15 ++++- lib/router/router.gr.dart | 113 +++++++++++++++++++++++--------------- lib/screens/home.dart | 39 +++++++++++++ 3 files changed, 119 insertions(+), 48 deletions(-) create mode 100644 lib/screens/home.dart diff --git a/lib/router/router.dart b/lib/router/router.dart index 40bcd9b..077e2d4 100644 --- a/lib/router/router.dart +++ b/lib/router/router.dart @@ -4,6 +4,8 @@ import 'package:pdg_app/screens/diary.dart'; import 'package:pdg_app/screens/login.dart'; import 'package:pdg_app/screens/register.dart'; +import '../screens/home.dart'; + @MaterialAutoRouter( // replaceInRouteName: 'Page,Route', routes: [ @@ -12,11 +14,18 @@ import 'package:pdg_app/screens/register.dart'; page: HomeScreen, initial: true, children: [ + RedirectRoute( + path: '', + redirectTo: 'diary', + ), AutoRoute( page: ChatScreen, - path: '/chat', - initial: true, + path: 'chat', ), + AutoRoute( + page: DiaryScreen, + path: 'diary', + ) ], ), AutoRoute( @@ -29,7 +38,7 @@ import 'package:pdg_app/screens/register.dart'; ), RedirectRoute( path: '*', - redirectTo: '/diary', + redirectTo: '/home/diary', ), ], ) diff --git a/lib/router/router.gr.dart b/lib/router/router.gr.dart index 6af72c6..eaa0838 100644 --- a/lib/router/router.gr.dart +++ b/lib/router/router.gr.dart @@ -11,80 +11,103 @@ // ignore_for_file: type=lint // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:auto_route/auto_route.dart' as _i5; -import 'package:flutter/material.dart' as _i6; +import 'package:auto_route/auto_route.dart' as _i6; +import 'package:flutter/material.dart' as _i7; -import '../screens/chat.dart' as _i2; -import '../screens/diary.dart' as _i1; -import '../screens/login.dart' as _i3; -import '../screens/register.dart' as _i4; +import '../screens/chat.dart' as _i4; +import '../screens/diary.dart' as _i5; +import '../screens/home.dart' as _i1; +import '../screens/login.dart' as _i2; +import '../screens/register.dart' as _i3; -class AppRouter extends _i5.RootStackRouter { - AppRouter([_i6.GlobalKey<_i6.NavigatorState>? navigatorKey]) +class AppRouter extends _i6.RootStackRouter { + AppRouter([_i7.GlobalKey<_i7.NavigatorState>? navigatorKey]) : super(navigatorKey); @override - final Map pagesMap = { - DiaryScreenRoute.name: (routeData) { - return _i5.MaterialPageX( - routeData: routeData, child: const _i1.DiaryScreen()); - }, - ChatScreenRoute.name: (routeData) { - return _i5.MaterialPageX( - routeData: routeData, child: const _i2.ChatScreen()); + final Map pagesMap = { + HomeScreenRoute.name: (routeData) { + return _i6.MaterialPageX( + routeData: routeData, child: const _i1.HomeScreen()); }, LoginScreenRoute.name: (routeData) { - return _i5.MaterialPageX( - routeData: routeData, child: const _i3.LoginScreen()); + return _i6.MaterialPageX( + routeData: routeData, child: const _i2.LoginScreen()); }, RegisterScreenRoute.name: (routeData) { - return _i5.MaterialPageX( - routeData: routeData, child: const _i4.RegisterScreen()); + return _i6.MaterialPageX( + routeData: routeData, child: const _i3.RegisterScreen()); + }, + ChatScreenRoute.name: (routeData) { + return _i6.MaterialPageX( + routeData: routeData, child: const _i4.ChatScreen()); + }, + DiaryScreenRoute.name: (routeData) { + return _i6.MaterialPageX( + routeData: routeData, child: const _i5.DiaryScreen()); } }; @override - List<_i5.RouteConfig> get routes => [ - _i5.RouteConfig('/#redirect', - path: '/', redirectTo: '/diary', fullMatch: true), - _i5.RouteConfig(DiaryScreenRoute.name, path: '/diary'), - _i5.RouteConfig(ChatScreenRoute.name, path: '/chat'), - _i5.RouteConfig(LoginScreenRoute.name, path: '/login'), - _i5.RouteConfig(RegisterScreenRoute.name, path: '/register'), - _i5.RouteConfig('*#redirect', - path: '*', redirectTo: '/diary', fullMatch: true) + List<_i6.RouteConfig> get routes => [ + _i6.RouteConfig('/#redirect', + path: '/', redirectTo: '/home', fullMatch: true), + _i6.RouteConfig(HomeScreenRoute.name, path: '/home', children: [ + _i6.RouteConfig('#redirect', + path: '', + parent: HomeScreenRoute.name, + redirectTo: 'diary', + fullMatch: true), + _i6.RouteConfig(ChatScreenRoute.name, + path: 'chat', parent: HomeScreenRoute.name), + _i6.RouteConfig(DiaryScreenRoute.name, + path: 'diary', parent: HomeScreenRoute.name) + ]), + _i6.RouteConfig(LoginScreenRoute.name, path: '/login'), + _i6.RouteConfig(RegisterScreenRoute.name, path: '/register'), + _i6.RouteConfig('*#redirect', + path: '*', redirectTo: '/home/diary', fullMatch: true) ]; } /// generated route for -/// [_i1.DiaryScreen] -class DiaryScreenRoute extends _i5.PageRouteInfo { - const DiaryScreenRoute() : super(DiaryScreenRoute.name, path: '/diary'); +/// [_i1.HomeScreen] +class HomeScreenRoute extends _i6.PageRouteInfo { + const HomeScreenRoute({List<_i6.PageRouteInfo>? children}) + : super(HomeScreenRoute.name, path: '/home', initialChildren: children); - static const String name = 'DiaryScreenRoute'; + static const String name = 'HomeScreenRoute'; } /// generated route for -/// [_i2.ChatScreen] -class ChatScreenRoute extends _i5.PageRouteInfo { - const ChatScreenRoute() : super(ChatScreenRoute.name, path: '/chat'); - - static const String name = 'ChatScreenRoute'; -} - -/// generated route for -/// [_i3.LoginScreen] -class LoginScreenRoute extends _i5.PageRouteInfo { +/// [_i2.LoginScreen] +class LoginScreenRoute extends _i6.PageRouteInfo { const LoginScreenRoute() : super(LoginScreenRoute.name, path: '/login'); static const String name = 'LoginScreenRoute'; } /// generated route for -/// [_i4.RegisterScreen] -class RegisterScreenRoute extends _i5.PageRouteInfo { +/// [_i3.RegisterScreen] +class RegisterScreenRoute extends _i6.PageRouteInfo { const RegisterScreenRoute() : super(RegisterScreenRoute.name, path: '/register'); static const String name = 'RegisterScreenRoute'; } + +/// generated route for +/// [_i4.ChatScreen] +class ChatScreenRoute extends _i6.PageRouteInfo { + const ChatScreenRoute() : super(ChatScreenRoute.name, path: 'chat'); + + static const String name = 'ChatScreenRoute'; +} + +/// generated route for +/// [_i5.DiaryScreen] +class DiaryScreenRoute extends _i6.PageRouteInfo { + const DiaryScreenRoute() : super(DiaryScreenRoute.name, path: 'diary'); + + static const String name = 'DiaryScreenRoute'; +} diff --git a/lib/screens/home.dart b/lib/screens/home.dart new file mode 100644 index 0000000..421e47c --- /dev/null +++ b/lib/screens/home.dart @@ -0,0 +1,39 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:pdg_app/router/router.gr.dart'; + +class HomeScreen extends StatelessWidget { + const HomeScreen({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return AutoTabsRouter( + routes: const [ + DiaryScreenRoute(), + ChatScreenRoute(), + ], + builder: (context, child, animation) { + final tabsRouter = AutoTabsRouter.of(context); + + return Scaffold( + body: FadeTransition( + opacity: animation, + child: child, + ), + bottomNavigationBar: BottomNavigationBar( + currentIndex: tabsRouter.activeIndex, + onTap: (index) { + tabsRouter.setActiveIndex(index); + }, + items: const [ + BottomNavigationBarItem(label: "chat", icon: Icon(Icons.chat)), + BottomNavigationBarItem( + label: "diary", icon: Icon(Icons.calendar_month)), + ], + ), + ); + }, + ); + } +} From 18429fd2ebcf086c57462f8c628118a36c616edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Mon, 29 Aug 2022 16:31:15 +0200 Subject: [PATCH 4/7] Add nav bar --- lib/screens/home.dart | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 421e47c..68ca933 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:pdg_app/router/router.gr.dart'; class HomeScreen extends StatelessWidget { @@ -21,15 +22,29 @@ class HomeScreen extends StatelessWidget { opacity: animation, child: child, ), - bottomNavigationBar: BottomNavigationBar( - currentIndex: tabsRouter.activeIndex, - onTap: (index) { - tabsRouter.setActiveIndex(index); - }, - items: const [ - BottomNavigationBarItem(label: "chat", icon: Icon(Icons.chat)), - BottomNavigationBarItem( - label: "diary", icon: Icon(Icons.calendar_month)), + bottomNavigationBar: GNav( + rippleColor: Theme.of(context).colorScheme.secondary, + hoverColor: Theme.of(context).colorScheme.secondary, + color: Theme.of(context).colorScheme.onSecondary, + activeColor: Theme.of(context).colorScheme.onSecondary, + duration: const Duration(milliseconds: 900), + tabBackgroundColor: Theme.of(context).colorScheme.secondary, + gap: 8, + padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 12), + tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), + tabs: const [ + GButton( + icon: Icons.chat_bubble_outline, + text: "Chat", + ), + GButton( + icon: Icons.calendar_month_outlined, + text: "Diary", + ), + GButton( + icon: Icons.account_circle_outlined, + text: "Profile", + ) ], ), ); From 0b62f88af8fab8fd4a35c37576b3265c6a8b4e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Tue, 30 Aug 2022 09:55:50 +0200 Subject: [PATCH 5/7] Page transition working --- lib/router/router.dart | 5 +++ lib/router/router.gr.dart | 67 ++++++++++++++++++++++++--------------- lib/screens/home.dart | 24 +++++++++++--- lib/screens/profile.dart | 10 ++++++ lib/widgets/navbar.dart | 0 5 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 lib/screens/profile.dart create mode 100644 lib/widgets/navbar.dart diff --git a/lib/router/router.dart b/lib/router/router.dart index 077e2d4..4983f39 100644 --- a/lib/router/router.dart +++ b/lib/router/router.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:pdg_app/screens/chat.dart'; import 'package:pdg_app/screens/diary.dart'; import 'package:pdg_app/screens/login.dart'; +import 'package:pdg_app/screens/profile.dart'; import 'package:pdg_app/screens/register.dart'; import '../screens/home.dart'; @@ -25,6 +26,10 @@ import '../screens/home.dart'; AutoRoute( page: DiaryScreen, path: 'diary', + ), + AutoRoute( + page: ProfileScreen, + path: 'my', ) ], ), diff --git a/lib/router/router.gr.dart b/lib/router/router.gr.dart index eaa0838..7ffbf6a 100644 --- a/lib/router/router.gr.dart +++ b/lib/router/router.gr.dart @@ -11,69 +11,76 @@ // ignore_for_file: type=lint // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:auto_route/auto_route.dart' as _i6; -import 'package:flutter/material.dart' as _i7; +import 'package:auto_route/auto_route.dart' as _i7; +import 'package:flutter/material.dart' as _i8; import '../screens/chat.dart' as _i4; import '../screens/diary.dart' as _i5; import '../screens/home.dart' as _i1; import '../screens/login.dart' as _i2; +import '../screens/profile.dart' as _i6; import '../screens/register.dart' as _i3; -class AppRouter extends _i6.RootStackRouter { - AppRouter([_i7.GlobalKey<_i7.NavigatorState>? navigatorKey]) +class AppRouter extends _i7.RootStackRouter { + AppRouter([_i8.GlobalKey<_i8.NavigatorState>? navigatorKey]) : super(navigatorKey); @override - final Map pagesMap = { + final Map pagesMap = { HomeScreenRoute.name: (routeData) { - return _i6.MaterialPageX( + return _i7.MaterialPageX( routeData: routeData, child: const _i1.HomeScreen()); }, LoginScreenRoute.name: (routeData) { - return _i6.MaterialPageX( + return _i7.MaterialPageX( routeData: routeData, child: const _i2.LoginScreen()); }, RegisterScreenRoute.name: (routeData) { - return _i6.MaterialPageX( + return _i7.MaterialPageX( routeData: routeData, child: const _i3.RegisterScreen()); }, ChatScreenRoute.name: (routeData) { - return _i6.MaterialPageX( + return _i7.MaterialPageX( routeData: routeData, child: const _i4.ChatScreen()); }, DiaryScreenRoute.name: (routeData) { - return _i6.MaterialPageX( + return _i7.MaterialPageX( routeData: routeData, child: const _i5.DiaryScreen()); + }, + ProfileScreenRoute.name: (routeData) { + return _i7.MaterialPageX( + routeData: routeData, child: const _i6.ProfileScreen()); } }; @override - List<_i6.RouteConfig> get routes => [ - _i6.RouteConfig('/#redirect', + List<_i7.RouteConfig> get routes => [ + _i7.RouteConfig('/#redirect', path: '/', redirectTo: '/home', fullMatch: true), - _i6.RouteConfig(HomeScreenRoute.name, path: '/home', children: [ - _i6.RouteConfig('#redirect', + _i7.RouteConfig(HomeScreenRoute.name, path: '/home', children: [ + _i7.RouteConfig('#redirect', path: '', parent: HomeScreenRoute.name, redirectTo: 'diary', fullMatch: true), - _i6.RouteConfig(ChatScreenRoute.name, + _i7.RouteConfig(ChatScreenRoute.name, path: 'chat', parent: HomeScreenRoute.name), - _i6.RouteConfig(DiaryScreenRoute.name, - path: 'diary', parent: HomeScreenRoute.name) + _i7.RouteConfig(DiaryScreenRoute.name, + path: 'diary', parent: HomeScreenRoute.name), + _i7.RouteConfig(ProfileScreenRoute.name, + path: 'my', parent: HomeScreenRoute.name) ]), - _i6.RouteConfig(LoginScreenRoute.name, path: '/login'), - _i6.RouteConfig(RegisterScreenRoute.name, path: '/register'), - _i6.RouteConfig('*#redirect', + _i7.RouteConfig(LoginScreenRoute.name, path: '/login'), + _i7.RouteConfig(RegisterScreenRoute.name, path: '/register'), + _i7.RouteConfig('*#redirect', path: '*', redirectTo: '/home/diary', fullMatch: true) ]; } /// generated route for /// [_i1.HomeScreen] -class HomeScreenRoute extends _i6.PageRouteInfo { - const HomeScreenRoute({List<_i6.PageRouteInfo>? children}) +class HomeScreenRoute extends _i7.PageRouteInfo { + const HomeScreenRoute({List<_i7.PageRouteInfo>? children}) : super(HomeScreenRoute.name, path: '/home', initialChildren: children); static const String name = 'HomeScreenRoute'; @@ -81,7 +88,7 @@ class HomeScreenRoute extends _i6.PageRouteInfo { /// generated route for /// [_i2.LoginScreen] -class LoginScreenRoute extends _i6.PageRouteInfo { +class LoginScreenRoute extends _i7.PageRouteInfo { const LoginScreenRoute() : super(LoginScreenRoute.name, path: '/login'); static const String name = 'LoginScreenRoute'; @@ -89,7 +96,7 @@ class LoginScreenRoute extends _i6.PageRouteInfo { /// generated route for /// [_i3.RegisterScreen] -class RegisterScreenRoute extends _i6.PageRouteInfo { +class RegisterScreenRoute extends _i7.PageRouteInfo { const RegisterScreenRoute() : super(RegisterScreenRoute.name, path: '/register'); @@ -98,7 +105,7 @@ class RegisterScreenRoute extends _i6.PageRouteInfo { /// generated route for /// [_i4.ChatScreen] -class ChatScreenRoute extends _i6.PageRouteInfo { +class ChatScreenRoute extends _i7.PageRouteInfo { const ChatScreenRoute() : super(ChatScreenRoute.name, path: 'chat'); static const String name = 'ChatScreenRoute'; @@ -106,8 +113,16 @@ class ChatScreenRoute extends _i6.PageRouteInfo { /// generated route for /// [_i5.DiaryScreen] -class DiaryScreenRoute extends _i6.PageRouteInfo { +class DiaryScreenRoute extends _i7.PageRouteInfo { const DiaryScreenRoute() : super(DiaryScreenRoute.name, path: 'diary'); static const String name = 'DiaryScreenRoute'; } + +/// generated route for +/// [_i6.ProfileScreen] +class ProfileScreenRoute extends _i7.PageRouteInfo { + const ProfileScreenRoute() : super(ProfileScreenRoute.name, path: 'my'); + + static const String name = 'ProfileScreenRoute'; +} diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 68ca933..541fd5d 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -4,15 +4,23 @@ import 'package:flutter/material.dart'; import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:pdg_app/router/router.gr.dart'; -class HomeScreen extends StatelessWidget { +class HomeScreen extends StatefulWidget { const HomeScreen({Key? key}) : super(key: key); + @override + State createState() => _HomeScreenState(); +} + +class _HomeScreenState extends State { + int _selectedIndex = 1; + @override Widget build(BuildContext context) { return AutoTabsRouter( routes: const [ - DiaryScreenRoute(), ChatScreenRoute(), + DiaryScreenRoute(), + ProfileScreenRoute(), ], builder: (context, child, animation) { final tabsRouter = AutoTabsRouter.of(context); @@ -30,8 +38,9 @@ class HomeScreen extends StatelessWidget { duration: const Duration(milliseconds: 900), tabBackgroundColor: Theme.of(context).colorScheme.secondary, gap: 8, - padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 12), - tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), + padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 15), + tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 25), + backgroundColor: Theme.of(context).colorScheme.surface, tabs: const [ GButton( icon: Icons.chat_bubble_outline, @@ -46,6 +55,13 @@ class HomeScreen extends StatelessWidget { text: "Profile", ) ], + selectedIndex: _selectedIndex, + onTabChange: (index) { + setState(() { + _selectedIndex = index; + tabsRouter.setActiveIndex(index); + }); + }, ), ); }, diff --git a/lib/screens/profile.dart b/lib/screens/profile.dart new file mode 100644 index 0000000..a7e3b07 --- /dev/null +++ b/lib/screens/profile.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class ProfileScreen extends StatelessWidget { + const ProfileScreen({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const Center(child: Text("Profile")); + } +} diff --git a/lib/widgets/navbar.dart b/lib/widgets/navbar.dart new file mode 100644 index 0000000..e69de29 From a8205f1d34c0e884223498329de40aa164e1cef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Tue, 30 Aug 2022 10:12:31 +0200 Subject: [PATCH 6/7] Navbar as a component --- lib/screens/home.dart | 40 +++------------------------- lib/widgets/navbar.dart | 53 ++++++++++++++++++++++++++++++++++++++ widgetbook/widgetbook.dart | 14 ++++++---- 3 files changed, 65 insertions(+), 42 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 541fd5d..835d7a7 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:pdg_app/router/router.gr.dart'; +import '../widgets/navbar.dart'; + class HomeScreen extends StatefulWidget { const HomeScreen({Key? key}) : super(key: key); @@ -12,8 +14,6 @@ class HomeScreen extends StatefulWidget { } class _HomeScreenState extends State { - int _selectedIndex = 1; - @override Widget build(BuildContext context) { return AutoTabsRouter( @@ -23,46 +23,12 @@ class _HomeScreenState extends State { ProfileScreenRoute(), ], builder: (context, child, animation) { - final tabsRouter = AutoTabsRouter.of(context); - return Scaffold( body: FadeTransition( opacity: animation, child: child, ), - bottomNavigationBar: GNav( - rippleColor: Theme.of(context).colorScheme.secondary, - hoverColor: Theme.of(context).colorScheme.secondary, - color: Theme.of(context).colorScheme.onSecondary, - activeColor: Theme.of(context).colorScheme.onSecondary, - duration: const Duration(milliseconds: 900), - tabBackgroundColor: Theme.of(context).colorScheme.secondary, - gap: 8, - padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 15), - tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 25), - backgroundColor: Theme.of(context).colorScheme.surface, - tabs: const [ - GButton( - icon: Icons.chat_bubble_outline, - text: "Chat", - ), - GButton( - icon: Icons.calendar_month_outlined, - text: "Diary", - ), - GButton( - icon: Icons.account_circle_outlined, - text: "Profile", - ) - ], - selectedIndex: _selectedIndex, - onTabChange: (index) { - setState(() { - _selectedIndex = index; - tabsRouter.setActiveIndex(index); - }); - }, - ), + bottomNavigationBar: const NavBar(), ); }, ); diff --git a/lib/widgets/navbar.dart b/lib/widgets/navbar.dart index e69de29..bdf8519 100644 --- a/lib/widgets/navbar.dart +++ b/lib/widgets/navbar.dart @@ -0,0 +1,53 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:google_nav_bar/google_nav_bar.dart'; + +class NavBar extends StatefulWidget { + const NavBar({Key? key}) : super(key: key); + + @override + State createState() => _NavBarState(); +} + +class _NavBarState extends State { + int _selectedIndex = 1; + + @override + Widget build(BuildContext context) { + final tabsRouter = AutoTabsRouter.of(context); + + return GNav( + rippleColor: Theme.of(context).colorScheme.secondary, + hoverColor: Theme.of(context).colorScheme.secondary, + color: Theme.of(context).colorScheme.onSecondary, + activeColor: Theme.of(context).colorScheme.onSecondary, + duration: const Duration(milliseconds: 900), + tabBackgroundColor: Theme.of(context).colorScheme.secondary, + gap: 8, + padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 15), + tabMargin: const EdgeInsets.symmetric(vertical: 15, horizontal: 25), + backgroundColor: Theme.of(context).colorScheme.surface, + tabs: const [ + GButton( + icon: Icons.chat_bubble_outline, + text: "Chat", + ), + GButton( + icon: Icons.calendar_month_outlined, + text: "Diary", + ), + GButton( + icon: Icons.account_circle_outlined, + text: "Profile", + ) + ], + selectedIndex: _selectedIndex, + onTabChange: (index) { + setState(() { + _selectedIndex = index; + tabsRouter.setActiveIndex(index); + }); + }, + ); + } +} diff --git a/widgetbook/widgetbook.dart b/widgetbook/widgetbook.dart index 9024063..948b2ff 100644 --- a/widgetbook/widgetbook.dart +++ b/widgetbook/widgetbook.dart @@ -12,6 +12,7 @@ import 'package:pdg_app/screens/register.dart'; import 'package:pdg_app/widgets/forms/main_text_field.dart'; import 'package:pdg_app/widgets/gradient_button.dart'; import 'package:pdg_app/widgets/cards/main_card.dart'; +import 'package:pdg_app/widgets/navbar.dart'; import 'package:pdg_app/widgets/right_arrow_button.dart'; import 'package:widgetbook/widgetbook.dart'; // ignore: depend_on_referenced_packages @@ -113,11 +114,14 @@ class HotReload extends StatelessWidget { ], ); - var actionButton = WidgetbookComponent(name: 'Action button', useCases: [ - WidgetbookUseCase( - name: 'Add', - builder: (context) => const ActionButton(icon: Icons.add)) - ]); + var actionButton = WidgetbookComponent( + name: 'Action button', + useCases: [ + WidgetbookUseCase( + name: 'Add', + builder: (context) => const ActionButton(icon: Icons.add)) + ], + ); var login = WidgetbookComponent( name: 'Login', From c71dca8b4109bcad10def6c9581eeb78057dd660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9?= Date: Tue, 30 Aug 2022 10:15:26 +0200 Subject: [PATCH 7/7] Fix linter --- lib/screens/home.dart | 2 -- widgetbook/widgetbook.dart | 1 - 2 files changed, 3 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 835d7a7..4581edf 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,7 +1,5 @@ import 'package:auto_route/auto_route.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:pdg_app/router/router.gr.dart'; import '../widgets/navbar.dart'; diff --git a/widgetbook/widgetbook.dart b/widgetbook/widgetbook.dart index 948b2ff..03d9ed9 100644 --- a/widgetbook/widgetbook.dart +++ b/widgetbook/widgetbook.dart @@ -12,7 +12,6 @@ import 'package:pdg_app/screens/register.dart'; import 'package:pdg_app/widgets/forms/main_text_field.dart'; import 'package:pdg_app/widgets/gradient_button.dart'; import 'package:pdg_app/widgets/cards/main_card.dart'; -import 'package:pdg_app/widgets/navbar.dart'; import 'package:pdg_app/widgets/right_arrow_button.dart'; import 'package:widgetbook/widgetbook.dart'; // ignore: depend_on_referenced_packages