diff --git a/lib/main.dart b/lib/main.dart index 4f59db3..8724130 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:developer'; import 'dart:io'; +import 'package:Bloomee/screens/widgets/snackbar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:Bloomee/blocs/add_to_playlist/cubit/add_to_playlist_cubit.dart'; @@ -81,6 +82,7 @@ class _MyAppState extends State { width: 50, height: 50, child: CircularProgressIndicator()); } else { return MaterialApp.router( + scaffoldMessengerKey: SnackbarService.messengerKey, routerConfig: GlobalRoutes().globalRouter, ); } diff --git a/lib/routes_and_consts/routes.dart b/lib/routes_and_consts/routes.dart index a32723c..9b2617a 100644 --- a/lib/routes_and_consts/routes.dart +++ b/lib/routes_and_consts/routes.dart @@ -9,7 +9,6 @@ import 'package:Bloomee/screens/screen/library_views/import_media_view.dart'; import 'package:Bloomee/screens/screen/library_views/playlist_screen.dart'; import 'package:Bloomee/screens/screen/offline_screen.dart'; import 'package:Bloomee/screens/screen/search_screen.dart'; -import 'package:Bloomee/screens/screen/test_screen.dart'; import 'package:Bloomee/screens/widgets/global_navbar.dart'; class GlobalRoutes { diff --git a/lib/screens/screen/home_views/notification_view.dart b/lib/screens/screen/home_views/notification_view.dart index a910d35..3c1b498 100644 --- a/lib/screens/screen/home_views/notification_view.dart +++ b/lib/screens/screen/home_views/notification_view.dart @@ -14,7 +14,7 @@ class NotificationView extends StatelessWidget { foregroundColor: Default_Theme.primaryColor1, title: Text( 'Notifications', - style: TextStyle( + style: const TextStyle( color: Default_Theme.primaryColor1, fontSize: 25, fontWeight: FontWeight.bold) @@ -22,7 +22,7 @@ class NotificationView extends StatelessWidget { ), ), body: const Center( - child: Text('GeeksForGeeks'), + child: Text('Bloomee Notifications View'), ), ); } diff --git a/lib/screens/screen/home_views/timer_view.dart b/lib/screens/screen/home_views/timer_view.dart index 20850b3..176cb23 100644 --- a/lib/screens/screen/home_views/timer_view.dart +++ b/lib/screens/screen/home_views/timer_view.dart @@ -14,7 +14,7 @@ class TimerView extends StatelessWidget { foregroundColor: Default_Theme.primaryColor1, title: Text( 'Timer', - style: TextStyle( + style: const TextStyle( color: Default_Theme.primaryColor1, fontSize: 25, fontWeight: FontWeight.bold) @@ -22,7 +22,7 @@ class TimerView extends StatelessWidget { ), ), body: const Center( - child: Text('GeeksForGeeks'), + child: Text('Bloomee Timer View'), ), ); } diff --git a/lib/screens/screen/offline_views/downloads_status.dart b/lib/screens/screen/offline_views/downloads_status.dart index 646eb9d..7e9f2ba 100644 --- a/lib/screens/screen/offline_views/downloads_status.dart +++ b/lib/screens/screen/offline_views/downloads_status.dart @@ -14,7 +14,7 @@ class DownloadsView extends StatelessWidget { foregroundColor: Default_Theme.primaryColor1, title: Text( 'Downloads', - style: TextStyle( + style: const TextStyle( color: Default_Theme.primaryColor1, fontSize: 25, fontWeight: FontWeight.bold) @@ -22,7 +22,7 @@ class DownloadsView extends StatelessWidget { ), ), body: const Center( - child: Text('GeeksForGeeks'), + child: Text('Bloomee Downloads View'), ), ); } diff --git a/lib/screens/widgets/snackbar.dart b/lib/screens/widgets/snackbar.dart new file mode 100644 index 0000000..bf64579 --- /dev/null +++ b/lib/screens/widgets/snackbar.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class SnackbarService { + static final GlobalKey messengerKey = + GlobalKey(); + + static void showMessage(String message, + {SnackBarAction? action, + Duration duration = const Duration(seconds: 2)}) { + messengerKey.currentState!.showSnackBar( + SnackBar( + content: Text(message, + style: const TextStyle(color: Colors.black, fontSize: 16)), + duration: duration, + showCloseIcon: false, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5), + ), + closeIconColor: Colors.black, + elevation: 0, + action: action, + backgroundColor: const Color.fromARGB(255, 231, 231, 231), + ), + ); + } +} diff --git a/lib/services/db/cubit/mediadb_cubit.dart b/lib/services/db/cubit/mediadb_cubit.dart index f8c04c5..f3e3319 100644 --- a/lib/services/db/cubit/mediadb_cubit.dart +++ b/lib/services/db/cubit/mediadb_cubit.dart @@ -1,7 +1,10 @@ import 'dart:developer'; +import 'package:Bloomee/screens/widgets/snackbar.dart'; +import 'package:Bloomee/theme_data/default.dart'; import 'package:audio_service/audio_service.dart'; import 'package:bloc/bloc.dart'; +import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; import 'package:rxdart/rxdart.dart'; import 'package:Bloomee/model/MediaPlaylistModel.dart'; @@ -18,11 +21,16 @@ class MediaDBCubit extends Cubit { addNewPlaylistToDB(MediaPlaylistDB(playlistName: "Liked")); } - Future addNewPlaylistToDB(MediaPlaylistDB mediaPlaylistDB) async { + Future addNewPlaylistToDB(MediaPlaylistDB mediaPlaylistDB, + {bool undo = false}) async { List _list = await getListOfPlaylists(); if (!_list.contains(mediaPlaylistDB.playlistName)) { isarDBService.addPlaylist(mediaPlaylistDB); refreshLibrary.add(true); + if (!undo) { + SnackbarService.showMessage( + "Playlist ${mediaPlaylistDB.playlistName} added"); + } } } @@ -63,6 +71,11 @@ class MediaDBCubit extends Cubit { refreshLibrary.add(true); isarDBService.likeMediaItem(MediaItem2MediaItemDB(mediaItem), isLiked: isLiked); + if (isLiked) { + SnackbarService.showMessage("${mediaItem.title} is Liked!!"); + } else { + SnackbarService.showMessage("${mediaItem.title} is Unliked!!"); + } } Future isLiked(MediaItem mediaItem) { @@ -166,19 +179,41 @@ class MediaDBCubit extends Cubit { Future removePlaylist(MediaPlaylistDB mediaPlaylistDB) async { isarDBService.removePlaylist(mediaPlaylistDB); + SnackbarService.showMessage("${mediaPlaylistDB.playlistName} is Deleted!!", + duration: const Duration(seconds: 3), + action: SnackBarAction( + label: "Undo", + textColor: Default_Theme.accentColor2, + onPressed: () => addNewPlaylistToDB(mediaPlaylistDB, undo: true), + )); } Future removeMediaFromPlaylist( MediaItem mediaItem, MediaPlaylistDB mediaPlaylistDB) async { MediaItemDB _mediaItemDB = MediaItem2MediaItemDB(mediaItem); - isarDBService.removeMediaItem(_mediaItemDB, mediaPlaylistDB); + isarDBService.removeMediaItem(_mediaItemDB, mediaPlaylistDB).then((value) { + SnackbarService.showMessage( + "${mediaItem.title} is removed from ${mediaPlaylistDB.playlistName}!!", + duration: const Duration(seconds: 3), + action: SnackBarAction( + label: "Undo", + textColor: Default_Theme.accentColor2, + onPressed: () => addMediaItemToPlaylist( + MediaItemDB2MediaItem(_mediaItemDB), mediaPlaylistDB, + undo: true))); + }); } Future addMediaItemToPlaylist( - MediaItemModel mediaItemModel, MediaPlaylistDB mediaPlaylistDB) async { + MediaItemModel mediaItemModel, MediaPlaylistDB mediaPlaylistDB, + {bool undo = false}) async { isarDBService.addMediaItem( MediaItem2MediaItemDB(mediaItemModel), mediaPlaylistDB); refreshLibrary.add(true); + if (!undo) { + SnackbarService.showMessage( + "${mediaItemModel.title} is added to ${mediaPlaylistDB.playlistName}!!"); + } } @override