Skip to content

Commit

Permalink
added snackbar and its implmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Feb 6, 2024
1 parent 6249989 commit 23191dd
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -81,6 +82,7 @@ class _MyAppState extends State<MyApp> {
width: 50, height: 50, child: CircularProgressIndicator());
} else {
return MaterialApp.router(
scaffoldMessengerKey: SnackbarService.messengerKey,
routerConfig: GlobalRoutes().globalRouter,
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/routes_and_consts/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/screen/home_views/notification_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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)
.merge(Default_Theme.secondoryTextStyle),
),
),
body: const Center(
child: Text('GeeksForGeeks'),
child: Text('Bloomee Notifications View'),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/screen/home_views/timer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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)
.merge(Default_Theme.secondoryTextStyle),
),
),
body: const Center(
child: Text('GeeksForGeeks'),
child: Text('Bloomee Timer View'),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/screen/offline_views/downloads_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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)
.merge(Default_Theme.secondoryTextStyle),
),
),
body: const Center(
child: Text('GeeksForGeeks'),
child: Text('Bloomee Downloads View'),
),
);
}
Expand Down
26 changes: 26 additions & 0 deletions lib/screens/widgets/snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

class SnackbarService {
static final GlobalKey<ScaffoldMessengerState> messengerKey =
GlobalKey<ScaffoldMessengerState>();

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),
),
);
}
}
41 changes: 38 additions & 3 deletions lib/services/db/cubit/mediadb_cubit.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,11 +21,16 @@ class MediaDBCubit extends Cubit<MediadbState> {
addNewPlaylistToDB(MediaPlaylistDB(playlistName: "Liked"));
}

Future<void> addNewPlaylistToDB(MediaPlaylistDB mediaPlaylistDB) async {
Future<void> addNewPlaylistToDB(MediaPlaylistDB mediaPlaylistDB,
{bool undo = false}) async {
List<String> _list = await getListOfPlaylists();
if (!_list.contains(mediaPlaylistDB.playlistName)) {
isarDBService.addPlaylist(mediaPlaylistDB);
refreshLibrary.add(true);
if (!undo) {
SnackbarService.showMessage(
"Playlist ${mediaPlaylistDB.playlistName} added");
}
}
}

Expand Down Expand Up @@ -63,6 +71,11 @@ class MediaDBCubit extends Cubit<MediadbState> {
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<bool> isLiked(MediaItem mediaItem) {
Expand Down Expand Up @@ -166,19 +179,41 @@ class MediaDBCubit extends Cubit<MediadbState> {

Future<void> 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<void> 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<void> 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
Expand Down

0 comments on commit 23191dd

Please sign in to comment.