From 19310793bf011b2f48b8e3ce88ef79a2832fa01b Mon Sep 17 00:00:00 2001 From: Augsorn Chanklad Date: Sun, 17 Mar 2024 10:40:20 +0700 Subject: [PATCH] Add Fluttertoast and fix add album collection --- .../album_collection_edit_modal.dart | 42 ++++++++++++++----- .../album_detail_controller.dart | 4 ++ pubspec.lock | 8 ++++ pubspec.yaml | 1 + 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/src/features/albums/presentation/album_detail_screen/album_collection_edit_modal.dart b/lib/src/features/albums/presentation/album_detail_screen/album_collection_edit_modal.dart index 14d8c45a..1793c077 100644 --- a/lib/src/features/albums/presentation/album_detail_screen/album_collection_edit_modal.dart +++ b/lib/src/features/albums/presentation/album_detail_screen/album_collection_edit_modal.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_rating_bar/flutter_rating_bar.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:go_router/go_router.dart'; import 'package:vocadb_app/src/common_widgets/simple_dropdown_input.dart'; import 'package:vocadb_app/src/constants/app_sizes.dart'; @@ -12,7 +13,8 @@ class AlbumCollectionEditModal { final Album album; - static const albumCollectionStatusModal = Key('album-collection-status-modal'); + static const albumCollectionStatusModal = + Key('album-collection-status-modal'); static const saveBtnKey = Key('save-btn-key'); static const statusDropdownKey = Key('status-dropdown-key'); static const mediaTypeDropdownKey = Key('media-type-dropdown-key'); @@ -20,6 +22,17 @@ class AlbumCollectionEditModal { AlbumCollectionEditModal(this.context, this.album); + _showToast() { + Fluttertoast.showToast( + msg: "Added to collection", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + timeInSecForIosWeb: 1, + textColor: Colors.white, + fontSize: 16.0, + ); + } + Widget build() { return SingleChildScrollView( key: albumCollectionStatusModal, @@ -45,8 +58,10 @@ class AlbumCollectionEditModal { value: value.purchaseStatus ?? 'Nothing', label: 'Status', onChanged: (value) { - ref.read(albumDetailControllerProvider(album.id).notifier) - .updatePurchaseStatus(value!); + ref + .read(albumDetailControllerProvider(album.id) + .notifier) + .updatePurchaseStatus(value!); }, items: const [ SimpleDropdownItem(name: 'Nothing', value: 'Nothing'), @@ -61,8 +76,10 @@ class AlbumCollectionEditModal { value: value.mediaType ?? 'Other', label: 'Media type', onChanged: (value) { - ref.read(albumDetailControllerProvider(album.id).notifier) - .updateMediaType(value!); + ref + .read(albumDetailControllerProvider(album.id) + .notifier) + .updateMediaType(value!); }, items: const [ SimpleDropdownItem( @@ -87,8 +104,10 @@ class AlbumCollectionEditModal { color: Colors.amber, ), onRatingUpdate: (rating) { - ref.read(albumDetailControllerProvider(album.id).notifier) - .updateRating(rating.toInt()); + ref + .read(albumDetailControllerProvider(album.id) + .notifier) + .updateRating(rating.toInt()); }, ), gapH16, @@ -97,9 +116,12 @@ class AlbumCollectionEditModal { ElevatedButton( key: saveBtnKey, onPressed: () { - ref.read(albumDetailControllerProvider(album.id).notifier) - .submitUpdateStatus(); - context.pop(); + ref + .read(albumDetailControllerProvider(album.id) + .notifier) + .submitUpdateStatus(); + _showToast(); + context.pop(); }, style: ElevatedButton.styleFrom( minimumSize: const Size.fromHeight(50), // NEW diff --git a/lib/src/features/albums/presentation/album_detail_screen/album_detail_controller.dart b/lib/src/features/albums/presentation/album_detail_screen/album_detail_controller.dart index dad78454..92074d4e 100644 --- a/lib/src/features/albums/presentation/album_detail_screen/album_detail_controller.dart +++ b/lib/src/features/albums/presentation/album_detail_screen/album_detail_controller.dart @@ -68,7 +68,11 @@ class AlbumDetailController extends StateNotifier { collectionStatus: currentStatus.purchaseStatus!, mediaType: currentStatus.mediaType!); await albumRepository.rateAlbum(album.id, albumRate); + if(state.albumCollection.album == null) { + state = state.copyWith(albumCollection: state.albumCollection.copyWith(album: state.album.value!)); + } } + } final albumDetailControllerProvider = StateNotifierProvider.autoDispose diff --git a/pubspec.lock b/pubspec.lock index bb32d71f..bdc6ecc3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -357,6 +357,14 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + sha256: "7a738eddad04c7b27a1ecfecd12e8ecd4b188cdd2d91c252a02a4aba65838c9d" + url: "https://pub.dev" + source: hosted + version: "8.1.1" font_awesome_flutter: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 25439763..8a31875a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,7 @@ dependencies: hive: 2.2.3 hive_flutter: 1.1.0 youtube_player_flutter: 8.1.2 + fluttertoast: 8.1.1 dev_dependencies: flutter_test: