Skip to content

Commit

Permalink
feat(navigation-ui): add per-screen topbar label
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOOSEIT committed Apr 8, 2024
1 parent e8f2f46 commit 40519fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -44,4 +46,13 @@ enum NavigationbarRoutes {
return const NotImplemented();
}
}

String pageLabel() {
switch (this) {
case challenge:
return "Your challenges";
case _:
return defaultLabelText;
}
}
}
7 changes: 5 additions & 2 deletions lib/views/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
6 changes: 3 additions & 3 deletions test/component/home/static_home_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -29,15 +29,15 @@ 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
final feedSortOptionList = find.byKey(HomeFeed.feedSortOptionKey);
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
Expand Down
6 changes: 3 additions & 3 deletions test/component/profile_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down

0 comments on commit 40519fb

Please sign in to comment.