From 787a36beb1f99bb956741e3366b6ae269b3d1da1 Mon Sep 17 00:00:00 2001 From: Augsorn Chanklad Date: Thu, 4 Apr 2024 22:53:11 +0700 Subject: [PATCH] Add shortcut menus on home screen --- .../presentation/home_screen/home_screen.dart | 42 ++++++++++++++++++- .../home_screen/shortcut_menu_button.dart | 31 ++++++++++++++ .../presentation/home_screen/home_robot.dart | 27 ++++++++++++ .../home_screen/home_screen_test.dart | 9 +++- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 lib/src/features/home/presentation/home_screen/shortcut_menu_button.dart diff --git a/lib/src/features/home/presentation/home_screen/home_screen.dart b/lib/src/features/home/presentation/home_screen/home_screen.dart index 3e090842..e3ca0c47 100644 --- a/lib/src/features/home/presentation/home_screen/home_screen.dart +++ b/lib/src/features/home/presentation/home_screen/home_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:vocadb_app/src/common_widgets/space_divider.dart'; import 'package:vocadb_app/src/constants/app_sizes.dart'; import 'package:vocadb_app/src/features/home/presentation/app_bar/app_title.dart'; import 'package:vocadb_app/src/features/home/presentation/app_bar/global_app_bar.dart'; @@ -7,19 +8,56 @@ import 'package:vocadb_app/src/features/home/presentation/home_screen/home_conte import 'package:vocadb_app/src/features/home/presentation/home_screen/random_albums_section.dart'; import 'package:vocadb_app/src/features/home/presentation/home_screen/recent_albums_section.dart'; import 'package:vocadb_app/src/features/home/presentation/home_screen/recent_events_section.dart'; +import 'package:vocadb_app/src/features/home/presentation/home_screen/shortcut_menu_button.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { - return const Scaffold( - appBar: GlobalAppBar( + return Scaffold( + appBar: const GlobalAppBar( title: AppTitle(), displayHome: false, ), body: HomeContentList( children: [ + const SpaceDivider.small(), + Center( + child: Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + alignment: WrapAlignment.start, + runAlignment: WrapAlignment.center, + runSpacing: 24.0, + children: [ + ShortcutMenuButton( + title: 'Songs', + iconData: Icons.music_note, + onPressed: () {}, + ), + ShortcutMenuButton( + title: 'Artists', + iconData: Icons.person, + onPressed: () {}, + ), + ShortcutMenuButton( + title: 'Albums', + iconData: Icons.album, + onPressed: () {}, + ), + ShortcutMenuButton( + title: 'Tags', + iconData: Icons.label, + onPressed: () {}, + ), + ShortcutMenuButton( + title: 'Events', + iconData: Icons.event, + onPressed: () {}, + ) + ], + ), + ), HighlightedSection(), RecentAlbumSection(), RandomAlbumSection(), diff --git a/lib/src/features/home/presentation/home_screen/shortcut_menu_button.dart b/lib/src/features/home/presentation/home_screen/shortcut_menu_button.dart new file mode 100644 index 00000000..4c520281 --- /dev/null +++ b/lib/src/features/home/presentation/home_screen/shortcut_menu_button.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; + +class ShortcutMenuButton extends StatelessWidget { + final String title; + final IconData iconData; + final VoidCallback onPressed; + + const ShortcutMenuButton( + {super.key, required this.title, required this.iconData, required this.onPressed}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + RawMaterialButton( + onPressed: onPressed, + shape: const CircleBorder(), + elevation: 2.0, + fillColor: Theme.of(context).cardColor, + padding: const EdgeInsets.all(15.0), + child: Icon( + iconData, + color: Theme.of(context).iconTheme.color, + size: 24.0, + ), + ), + Text(title) + ], + ); + } +} \ No newline at end of file diff --git a/test/src/features/home/presentation/home_screen/home_robot.dart b/test/src/features/home/presentation/home_screen/home_robot.dart index 7dc753e7..505bc466 100644 --- a/test/src/features/home/presentation/home_screen/home_robot.dart +++ b/test/src/features/home/presentation/home_screen/home_robot.dart @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:vocadb_app/src/features/albums/data/album_repository.dart'; import 'package:vocadb_app/src/features/home/presentation/home_screen/home_screen.dart'; +import 'package:vocadb_app/src/features/home/presentation/home_screen/shortcut_menu_button.dart'; import 'package:vocadb_app/src/features/releaseEvents/data/release_event_repository.dart'; import 'package:vocadb_app/src/features/songs/data/song_repository.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -42,4 +43,30 @@ class HomeRobot { await tester.drag(find.byType(ListView), Offset(0, offset)); await tester.pump(); } + + Future expectShortcutSongSearchIsVisible(bool visible) async { + final finder = find.widgetWithText(ShortcutMenuButton, 'Songs'); + (visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing); + } + + Future expectShortcutArtistSearchIsVisible(bool visible) async { + final finder = find.widgetWithText(ShortcutMenuButton, 'Artists'); + (visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing); + } + + Future expectShortcutAlbumSearchIsVisible(bool visible) async { + final finder = find.widgetWithText(ShortcutMenuButton, 'Albums'); + (visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing); + } + + Future expectShortcutTagSearchIsVisible(bool visible) async { + final finder = find.widgetWithText(ShortcutMenuButton, 'Tags'); + (visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing); + } + + Future expectShortcutEventSearchIsVisible(bool visible) async { + final finder = find.widgetWithText(ShortcutMenuButton, 'Events'); + (visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing); + } + } diff --git a/test/src/features/home/presentation/home_screen/home_screen_test.dart b/test/src/features/home/presentation/home_screen/home_screen_test.dart index c81be490..9a0fc685 100644 --- a/test/src/features/home/presentation/home_screen/home_screen_test.dart +++ b/test/src/features/home/presentation/home_screen/home_screen_test.dart @@ -5,7 +5,7 @@ import '../../../../mocks.dart'; import 'home_robot.dart'; void main() { - testWidgets('home screen ...', (tester) async { + testWidgets('Render home screen correctly', (tester) async { final r = HomeRobot(tester); final songRepository = MockSongRepository(); final albumRepository = MockAlbumRepository(); @@ -17,6 +17,13 @@ void main() { releaseEventRepository: releaseEventRepository, ); + // Verify Shortcut menus + await r.expectShortcutSongSearchIsVisible(true); + await r.expectShortcutArtistSearchIsVisible(true); + await r.expectShortcutAlbumSearchIsVisible(true); + await r.expectShortcutTagSearchIsVisible(true); + await r.expectShortcutEventSearchIsVisible(true); + await r.scrollDown(); verify(songRepository.fetchSongsHighlighted).called(1);