From 197be6330b3585441fe2ca9c6ceaa4f630fbd96e Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sat, 6 Aug 2022 02:25:55 +0300 Subject: [PATCH] fix: show toast error and fallback icon when album art fails to load --- .../lyricsgrabbr/NotificationListener.kt | 2 +- lib/lyrics.dart | 1 - lib/search_result.dart | 12 ++++++++++++ pubspec.lock | 7 +++++++ pubspec.yaml | 3 ++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/com/illusionware/lyricsgrabbr/lyricsgrabbr/NotificationListener.kt b/android/app/src/main/kotlin/com/illusionware/lyricsgrabbr/lyricsgrabbr/NotificationListener.kt index dd96e7a..6d178dc 100644 --- a/android/app/src/main/kotlin/com/illusionware/lyricsgrabbr/lyricsgrabbr/NotificationListener.kt +++ b/android/app/src/main/kotlin/com/illusionware/lyricsgrabbr/lyricsgrabbr/NotificationListener.kt @@ -61,7 +61,7 @@ class NotificationListener : NotificationListenerService() { private fun getStopServiceNotificationAction(): PendingIntent { val intent = Intent(MainActivity.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0) + val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE) return pendingIntent } diff --git a/lib/lyrics.dart b/lib/lyrics.dart index 608e1e1..7d91511 100644 --- a/lib/lyrics.dart +++ b/lib/lyrics.dart @@ -45,7 +45,6 @@ class _LyricsPageState extends State { lyrics = fullLyrics; fetching = false; }); - // print(thing); } } diff --git a/lib/search_result.dart b/lib/search_result.dart index ff48127..96c929c 100644 --- a/lib/search_result.dart +++ b/lib/search_result.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'lyrics.dart'; @@ -135,6 +136,17 @@ class _SearchResultState extends State { width: 75, height: 75, fit: BoxFit.cover, + errorBuilder: (context, error, stackTrace) { + Fluttertoast.showToast( + msg: 'Failed to load album art for: ${widget.title}', + toastLength: Toast.LENGTH_LONG); + return const Center( + child: SizedBox( + width: 75, + height: 75, + child: Icon(Icons.broken_image, size: 40)), + ); + }, ), ), Flexible( diff --git a/pubspec.lock b/pubspec.lock index a2e4052..ea05e02 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -128,6 +128,13 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.dartlang.org" + source: hosted + version: "8.0.9" html: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ac00aed..11428a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.2.0+1 +version: 0.2.1+1 environment: sdk: ">=2.16.1 <3.0.0" @@ -34,6 +34,7 @@ dependencies: flutter_local_notifications: ^9.3.2 url_launcher: ^6.0.20 web_scraper: ^0.1.4 + fluttertoast: ^8.0.9 dev_dependencies: flutter_test: