From 40519fb9447598bcb100d7095591f77d6f2ce62a Mon Sep 17 00:00:00 2001 From: CHOOSEIT Date: Mon, 8 Apr 2024 11:31:43 +0200 Subject: [PATCH] feat(navigation-ui): add per-screen topbar label --- .../bottom_navigation_bar/navigation_bar_routes.dart | 11 +++++++++++ lib/views/pages/home/home_page.dart | 7 +++++-- .../top_bar/{home_top_bar.dart => app_top_bar.dart} | 8 ++++---- test/component/home/static_home_test.dart | 6 +++--- test/component/profile_page_test.dart | 6 +++--- 5 files changed, 26 insertions(+), 12 deletions(-) rename lib/views/pages/home/top_bar/{home_top_bar.dart => app_top_bar.dart} (89%) diff --git a/lib/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart b/lib/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart index 322303fe..5f37119f 100644 --- a/lib/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart +++ b/lib/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart @@ -19,6 +19,8 @@ enum NavigationbarRoutes { group("Group", Icon(Icons.group), null), map("Map", Icon(Icons.place), null); + static const defaultLabelText = "Proxima"; + final String name; final Widget icon; @@ -44,4 +46,13 @@ enum NavigationbarRoutes { return const NotImplemented(); } } + + String pageLabel() { + switch (this) { + case challenge: + return "Your challenges"; + case _: + return defaultLabelText; + } + } } diff --git a/lib/views/pages/home/home_page.dart b/lib/views/pages/home/home_page.dart index e5856c98..5a235c81 100644 --- a/lib/views/pages/home/home_page.dart +++ b/lib/views/pages/home/home_page.dart @@ -5,7 +5,7 @@ import "package:proxima/viewmodels/login_view_model.dart"; import "package:proxima/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart"; import "package:proxima/views/navigation/bottom_navigation_bar/navigation_bottom_bar.dart"; import "package:proxima/views/navigation/routes.dart"; -import "package:proxima/views/pages/home/top_bar/home_top_bar.dart"; +import "package:proxima/views/pages/home/top_bar/app_top_bar.dart"; class HomePage extends HookConsumerWidget { const HomePage({super.key}); @@ -27,7 +27,10 @@ class HomePage extends HookConsumerWidget { return Scaffold( appBar: AppBar( - title: const HomeTopBar(), + title: AppTopBar( + labelText: + NavigationbarRoutes.values[currentPageIndex.value].pageLabel(), + ), ), bottomNavigationBar: NavigationBottomBar( selectedIndex: currentPageIndex, diff --git a/lib/views/pages/home/top_bar/home_top_bar.dart b/lib/views/pages/home/top_bar/app_top_bar.dart similarity index 89% rename from lib/views/pages/home/top_bar/home_top_bar.dart rename to lib/views/pages/home/top_bar/app_top_bar.dart index 0083f5e8..50667ba7 100644 --- a/lib/views/pages/home/top_bar/home_top_bar.dart +++ b/lib/views/pages/home/top_bar/app_top_bar.dart @@ -4,18 +4,18 @@ import "package:proxima/views/navigation/routes.dart"; /// This widget is the top bar of the home page /// It contains the feed sort option and the user profile picture -class HomeTopBar extends HookConsumerWidget { +class AppTopBar extends HookConsumerWidget { static const homeTopBarKey = Key("homeTopBar"); static const profilePictureKey = Key("profilePicture"); - static const titleText = "Proxima"; + final String labelText; - const HomeTopBar({super.key}); + const AppTopBar({super.key, required this.labelText}); @override Widget build(BuildContext context, WidgetRef ref) { final title = Text( - titleText, + labelText, style: Theme.of(context).textTheme.headlineMedium, ); diff --git a/test/component/home/static_home_test.dart b/test/component/home/static_home_test.dart index 0d96fe7c..fcf50b85 100644 --- a/test/component/home/static_home_test.dart +++ b/test/component/home/static_home_test.dart @@ -7,7 +7,7 @@ import "package:proxima/views/content/feed/post_card/post_card.dart"; import "package:proxima/views/navigation/bottom_navigation_bar/navigation_bar_routes.dart"; import "package:proxima/views/navigation/bottom_navigation_bar/navigation_bottom_bar.dart"; import "package:proxima/views/pages/home/home_page.dart"; -import "package:proxima/views/pages/home/top_bar/home_top_bar.dart"; +import "package:proxima/views/pages/home/top_bar/app_top_bar.dart"; import "../utils/mock_data/home/mock_posts.dart"; @@ -29,7 +29,7 @@ void main() { expect(homePage, findsOneWidget); // Check that the top bar is displayed - final topBar = find.byKey(HomeTopBar.homeTopBarKey); + final topBar = find.byKey(AppTopBar.homeTopBarKey); expect(topBar, findsOneWidget); //Check sort option list is displayed @@ -37,7 +37,7 @@ void main() { expect(feedSortOptionList, findsOneWidget); //Check profile picture is displayed - final profilePicture = find.byKey(HomeTopBar.profilePictureKey); + final profilePicture = find.byKey(AppTopBar.profilePictureKey); expect(profilePicture, findsOneWidget); // Check that the bottom bar is displayed diff --git a/test/component/profile_page_test.dart b/test/component/profile_page_test.dart index 4fd821c9..fc9deebe 100644 --- a/test/component/profile_page_test.dart +++ b/test/component/profile_page_test.dart @@ -5,7 +5,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart"; import "package:proxima/services/login_service.dart"; import "package:proxima/views/navigation/routes.dart"; import "package:proxima/views/pages/home/home_page.dart"; -import "package:proxima/views/pages/home/top_bar/home_top_bar.dart"; +import "package:proxima/views/pages/home/top_bar/app_top_bar.dart"; import "package:proxima/views/pages/profile/posts_info/info_card.dart"; import "package:proxima/views/pages/profile/posts_info/info_column.dart"; import "package:proxima/views/pages/profile/posts_info/info_row.dart"; @@ -28,11 +28,11 @@ void main() { await tester.pumpAndSettle(); // Check that the top bar is displayed - final topBar = find.byKey(HomeTopBar.homeTopBarKey); + final topBar = find.byKey(AppTopBar.homeTopBarKey); expect(topBar, findsOneWidget); //Check profile picture is displayed - final profilePicture = find.byKey(HomeTopBar.profilePictureKey); + final profilePicture = find.byKey(AppTopBar.profilePictureKey); expect(profilePicture, findsOneWidget); // Tap on the profile picture