Skip to content

Commit

Permalink
Add Fluttertoast and fix add album collection
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 17, 2024
1 parent c39ae02 commit 1931079
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,14 +13,26 @@ 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');
static const ratingBarDropdownKey = Key('rating-bar-dropdown-key');

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,
Expand All @@ -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'),
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class AlbumDetailController extends StateNotifier<AlbumDetailState> {
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
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1931079

Please sign in to comment.