From 1ea9fdfc2d4e4b917aa2ca2b2e41a053f58f8c9b Mon Sep 17 00:00:00 2001 From: Augsorn Chanklad Date: Thu, 14 Mar 2024 11:08:27 +0700 Subject: [PATCH] Add tap to entry detail --- lib/src/features/entries/domain/entry.dart | 8 +++++++ .../entries_search_result.dart | 6 ++++- lib/src/routing/app_route_context.dart | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/src/features/entries/domain/entry.dart b/lib/src/features/entries/domain/entry.dart index f1247db5..1c61a901 100644 --- a/lib/src/features/entries/domain/entry.dart +++ b/lib/src/features/entries/domain/entry.dart @@ -8,6 +8,7 @@ import 'package:vocadb_app/src/features/artists/domain/artist.dart'; import 'package:vocadb_app/src/features/entries/domain/main_picture.dart'; import 'package:vocadb_app/src/features/releaseEvents/domain/release_event.dart'; import 'package:vocadb_app/src/features/songs/domain/song.dart'; +import 'package:vocadb_app/src/features/tags/domain/tag.dart'; import 'package:vocadb_app/src/features/tags/domain/tag_usage.dart'; import 'package:vocadb_app/src/features/weblinks/domain/web_link.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -88,6 +89,13 @@ extension EntryExtended on Entry { ); } + Tag toTag() { + return Tag( + id: id, + name: name, + ); + } + String get imageUrl { if (mainPicture == null || mainPicture!.urlOriginal == null) { return kPlaceholderImageUrl; diff --git a/lib/src/features/entries/presentation/entries_search_screen/entries_search_result.dart b/lib/src/features/entries/presentation/entries_search_screen/entries_search_result.dart index 221e35de..9bea55c6 100644 --- a/lib/src/features/entries/presentation/entries_search_screen/entries_search_result.dart +++ b/lib/src/features/entries/presentation/entries_search_screen/entries_search_result.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; import 'package:vocadb_app/src/common_widgets/custom_network_image.dart'; import 'package:vocadb_app/src/features/entries/domain/entry.dart'; +import 'package:vocadb_app/src/routing/app_route_context.dart'; class EntriesSearchResult extends StatelessWidget { const EntriesSearchResult({super.key, required this.entries}); @@ -21,7 +23,9 @@ class EntriesSearchResult extends StatelessWidget { ), title: Text(entry.name ?? ''), subtitle: Text(entry.entryType), - onTap: () {}, + onTap: () { + context.goEntryDetail(entry); + }, ); }), ); diff --git a/lib/src/routing/app_route_context.dart b/lib/src/routing/app_route_context.dart index 333b8744..83bf139b 100644 --- a/lib/src/routing/app_route_context.dart +++ b/lib/src/routing/app_route_context.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:go_router/go_router.dart'; import 'package:vocadb_app/src/features/albums/domain/album.dart'; import 'package:vocadb_app/src/features/artists/domain/artist.dart'; +import 'package:vocadb_app/src/features/entries/domain/entry.dart'; import 'package:vocadb_app/src/features/releaseEvents/domain/release_event.dart'; import 'package:vocadb_app/src/features/songs/domain/song.dart'; import 'package:vocadb_app/src/features/tags/domain/tag.dart'; @@ -33,6 +34,29 @@ extension AppRouteContext on BuildContext { } + Future goEntryDetail(Entry entry) async { + String entryType = entry.entryType; + switch (entryType) { + case 'Album': + goAlbumDetail(entry.toAlbum()); + break; + case 'Artist': + goArtistDetail(entry.toArtist()); + break; + case 'Song': + goSongDetail(entry.toSong()); + break; + case 'Tag': + goTagDetail(entry.toTag()); + break; + case 'ReleaseEvent': + goReleaseEventDetail(entry.toReleaseEvent()); + break; + default: + throw Exception('Unsupported entry type: $entryType'); + } + } + Future goLogin() async { goNamed(AppRoute.signIn.name); }