Skip to content

Commit

Permalink
Add shortcut menus on home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Apr 4, 2024
1 parent 6e613a3 commit 787a36b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
42 changes: 40 additions & 2 deletions lib/src/features/home/presentation/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: <Widget>[
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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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: <Widget>[
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)
],
);
}
}
27 changes: 27 additions & 0 deletions test/src/features/home/presentation/home_screen/home_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,4 +43,30 @@ class HomeRobot {
await tester.drag(find.byType(ListView), Offset(0, offset));
await tester.pump();
}

Future<void> expectShortcutSongSearchIsVisible(bool visible) async {
final finder = find.widgetWithText(ShortcutMenuButton, 'Songs');
(visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing);
}

Future<void> expectShortcutArtistSearchIsVisible(bool visible) async {
final finder = find.widgetWithText(ShortcutMenuButton, 'Artists');
(visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing);
}

Future<void> expectShortcutAlbumSearchIsVisible(bool visible) async {
final finder = find.widgetWithText(ShortcutMenuButton, 'Albums');
(visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing);
}

Future<void> expectShortcutTagSearchIsVisible(bool visible) async {
final finder = find.widgetWithText(ShortcutMenuButton, 'Tags');
(visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing);
}

Future<void> expectShortcutEventSearchIsVisible(bool visible) async {
final finder = find.widgetWithText(ShortcutMenuButton, 'Events');
(visible) ? expect(finder, findsOneWidget) : expect(finder, findsNothing);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 787a36b

Please sign in to comment.