From fdbb7986912041b4461b5d70477fa0cec8bfbd6e Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Wed, 19 Jun 2024 14:58:08 +0800 Subject: [PATCH] Unify exception snackbar handling --- app/lib/exception_util.dart | 23 +++++++++++++++++ app/lib/internal_download_handler.dart | 11 ++------ app/lib/legacy/connect.dart | 16 +++--------- app/lib/set_as_handler.dart | 7 +----- app/lib/share_handler.dart | 16 +++--------- app/lib/snack_bar_manager.dart | 11 ++++++++ app/lib/widget/album_importer.dart | 11 ++------ .../widget/album_share_outlier_browser.dart | 17 +++---------- app/lib/widget/archive_browser.dart | 6 +---- app/lib/widget/collection_browser.dart | 25 ++++++++++--------- app/lib/widget/collection_picker.dart | 7 +----- app/lib/widget/dir_picker.dart | 16 +++--------- app/lib/widget/home_collections.dart | 6 +---- app/lib/widget/home_photos2.dart | 24 ++++++++++-------- app/lib/widget/home_search.dart | 6 +---- app/lib/widget/home_search_suggestion.dart | 7 +----- app/lib/widget/live_photo_viewer.dart | 11 ++------ app/lib/widget/people_browser.dart | 6 +---- app/lib/widget/places_browser.dart | 7 +----- app/lib/widget/result_viewer.dart | 6 +---- app/lib/widget/search_landing.dart | 7 +----- app/lib/widget/settings/account_settings.dart | 22 ++++++++-------- .../widget/settings/collection_settings.dart | 8 +----- .../widget/settings/developer_settings.dart | 7 +----- .../widget/settings/enhancement_settings.dart | 8 +----- app/lib/widget/settings/expert_settings.dart | 7 +----- .../widget/settings/language_settings.dart | 7 +----- .../widget/settings/metadata_settings.dart | 8 +----- app/lib/widget/settings/misc_settings.dart | 8 +----- app/lib/widget/settings/photos_settings.dart | 8 +----- app/lib/widget/settings/theme_settings.dart | 8 +----- app/lib/widget/settings/viewer_settings.dart | 8 +----- app/lib/widget/shared_file_viewer.dart | 6 +---- app/lib/widget/sharing_browser.dart | 7 +----- app/lib/widget/tag_picker_dialog.dart | 6 +---- app/lib/widget/trashbin_browser.dart | 6 +---- app/lib/widget/video_viewer.dart | 11 ++------ 37 files changed, 116 insertions(+), 265 deletions(-) diff --git a/app/lib/exception_util.dart b/app/lib/exception_util.dart index 3555412f..e0b8ae80 100644 --- a/app/lib/exception_util.dart +++ b/app/lib/exception_util.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:flutter/material.dart'; import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/exception.dart'; @@ -26,3 +27,25 @@ String toUserString(Object? exception) { } return exception?.toString() ?? "Unknown error"; } + +(String text, SnackBarAction? action) exceptionToSnackBarData( + Object? exception) { + if (exception is ApiException) { + if (exception.response.statusCode == 401) { + return (L10n.global().errorUnauthenticated, null); + } else if (exception.response.statusCode == 404) { + return ("HTTP 404 not found", null); + } else if (exception.response.statusCode == 423) { + return (L10n.global().errorLocked, null); + } else if (exception.response.statusCode == 500) { + return (L10n.global().errorServerError, null); + } + } else if (exception is SocketException) { + return (L10n.global().errorDisconnected, null); + } else if (exception is InvalidBaseUrlException) { + return (L10n.global().errorInvalidBaseUrl, null); + } else if (exception is AlbumDowngradeException) { + return (L10n.global().errorAlbumDowngrade, null); + } + return (exception?.toString() ?? "Unknown error", null); +} diff --git a/app/lib/internal_download_handler.dart b/app/lib/internal_download_handler.dart index 4a2c67b1..282daf05 100644 --- a/app/lib/internal_download_handler.dart +++ b/app/lib/internal_download_handler.dart @@ -8,7 +8,6 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/platform/download.dart'; import 'package:nc_photos/snack_bar_manager.dart'; @@ -84,10 +83,7 @@ class InternalDownloadHandler { } catch (e, stacktrace) { _log.shout( "[downloadPreviews] Failed while DownloadPreview", e, stacktrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } return results.toMap(); @@ -156,10 +152,7 @@ class InternalDownloadHandler { } catch (e, stacktrace) { _log.shout( "[downloadFiles] Failed while downloadFile", e, stacktrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } return results.toMap(); diff --git a/app/lib/legacy/connect.dart b/app/lib/legacy/connect.dart index c5540e51..6927dae1 100644 --- a/app/lib/legacy/connect.dart +++ b/app/lib/legacy/connect.dart @@ -9,7 +9,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/help_utils.dart' as help_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/legacy/app_password_exchange_bloc.dart'; @@ -121,10 +120,7 @@ class _ConnectState extends State { )); Navigator.of(context).pop(null); } else { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); Navigator.of(context).pop(null); } } @@ -181,10 +177,7 @@ class _ConnectState extends State { if (e.response.statusCode == 404) { return _onCheckWebDavUrlFailed(context, account); } - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); Navigator.of(context).pop(null); } on StateError catch (_) { // Nextcloud for some reason doesn't return HTTP error when listing home @@ -192,10 +185,7 @@ class _ConnectState extends State { return _onCheckWebDavUrlFailed(context, account); } catch (e, stackTrace) { _log.shout("[_checkWebDavUrl] Failed", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); Navigator.of(context).pop(null); } } diff --git a/app/lib/set_as_handler.dart b/app/lib/set_as_handler.dart index d09894ef..3f2fb8ac 100644 --- a/app/lib/set_as_handler.dart +++ b/app/lib/set_as_handler.dart @@ -6,9 +6,7 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/internal_download_handler.dart'; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/share.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/inflate_file_descriptor.dart'; @@ -41,10 +39,7 @@ class SetAsHandler { } } catch (e, stackTrace) { _log.shout("[setAsFile] Failed while sharing files", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } finally { if (!isSelectionCleared) { clearSelection?.call(); diff --git a/app/lib/share_handler.dart b/app/lib/share_handler.dart index 1b374d8b..a081b165 100644 --- a/app/lib/share_handler.dart +++ b/app/lib/share_handler.dart @@ -16,7 +16,6 @@ import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/local_file.dart'; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/share/data_source.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/internal_download_handler.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/share.dart'; @@ -62,10 +61,7 @@ class ShareHandler { e, stackTrace); if (!hasShownError) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); hasShownError = true; } } @@ -91,10 +87,7 @@ class ShareHandler { } } catch (e, stackTrace) { _log.shout("[shareFiles] Failed while sharing files", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } finally { if (!isSelectionCleared) { clearSelection?.call(); @@ -199,10 +192,7 @@ class ShareHandler { } catch (e, stackTrace) { _log.shout( "[_shareFileAsLink] Failed while CreateLinkShare", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } diff --git a/app/lib/snack_bar_manager.dart b/app/lib/snack_bar_manager.dart index dabb1552..fb064f03 100644 --- a/app/lib/snack_bar_manager.dart +++ b/app/lib/snack_bar_manager.dart @@ -2,6 +2,8 @@ import 'dart:collection'; import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; +import 'package:nc_photos/exception_util.dart'; +import 'package:nc_photos/k.dart' as k; import 'package:np_codegen/np_codegen.dart'; part 'snack_bar_manager.g.dart'; @@ -40,6 +42,15 @@ class SnackBarManager { _ensureRunning(); } + void showSnackBarForException(Object? exception) { + final (text, action) = exceptionToSnackBarData(exception); + showSnackBar(SnackBar( + content: Text(text), + action: action, + duration: k.snackBarDurationNormal, + )); + } + void _ensureRunning() { if (!_isRunning) { _isRunning = true; diff --git a/app/lib/widget/album_importer.dart b/app/lib/widget/album_importer.dart index 426a3a77..2613089f 100644 --- a/app/lib/widget/album_importer.dart +++ b/app/lib/widget/album_importer.dart @@ -16,7 +16,6 @@ import 'package:nc_photos/entity/album/sort_provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/album/create_album.dart'; @@ -210,10 +209,7 @@ class _AlbumImporterState extends State { state is ListImportableAlbumBlocLoading) { _transformItems(state.items); } else if (state is ListImportableAlbumBlocFailure) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } @@ -258,10 +254,7 @@ class _AlbumImporterState extends State { } catch (e, stacktrace) { _log.shout( "[_createAllAlbums] Failed creating dir album", e, stacktrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } } diff --git a/app/lib/widget/album_share_outlier_browser.dart b/app/lib/widget/album_share_outlier_browser.dart index a7281ead..2c92bcf1 100644 --- a/app/lib/widget/album_share_outlier_browser.dart +++ b/app/lib/widget/album_share_outlier_browser.dart @@ -11,8 +11,6 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/share/data_source.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/create_share.dart'; import 'package:nc_photos/use_case/remove_share.dart'; @@ -314,10 +312,7 @@ class _AlbumShareOutlierBrowserState extends State { _transformItems(state.items); } else if (state is ListAlbumShareOutlierBlocFailure) { _transformItems(state.items); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } @@ -384,10 +379,7 @@ class _AlbumShareOutlierBrowserState extends State { } catch (e, stackTrace) { _log.shout( "[_fixMissingSharee] Failed while CreateUserShare", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); if (mounted) { setState(() { _removeItemStatus(item.file.fdPath, item.shareWith); @@ -412,10 +404,7 @@ class _AlbumShareOutlierBrowserState extends State { } } catch (e, stackTrace) { _log.shout("[_fixExtraShare] Failed while RemoveShare", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); if (mounted) { setState(() { _removeItemStatus(item.file.fdPath, item.share.shareWith!); diff --git a/app/lib/widget/archive_browser.dart b/app/lib/widget/archive_browser.dart index f63af2f7..70ca8bf2 100644 --- a/app/lib/widget/archive_browser.dart +++ b/app/lib/widget/archive_browser.dart @@ -15,7 +15,6 @@ import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/flutter_util.dart' as flutter_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; @@ -103,10 +102,7 @@ class _WrappedArchiveBrowserState extends State<_WrappedArchiveBrowser> duration: k.snackBarDurationNormal, )); } else { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(error.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(error.error); } } }, diff --git a/app/lib/widget/collection_browser.dart b/app/lib/widget/collection_browser.dart index 45025448..ff1feb49 100644 --- a/app/lib/widget/collection_browser.dart +++ b/app/lib/widget/collection_browser.dart @@ -35,7 +35,6 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/flutter_util.dart' as flutter_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; @@ -216,21 +215,23 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser> selector: (state) => state.error, listener: (context, error) { if (error != null && isPageVisible()) { - final String content; if (error.error is _ArchiveFailedError) { - content = L10n.global() - .archiveSelectedFailureNotification( - (error.error as _ArchiveFailedError).count); + SnackBarManager().showSnackBar(SnackBar( + content: Text(L10n.global() + .archiveSelectedFailureNotification( + (error.error as _ArchiveFailedError).count)), + duration: k.snackBarDurationNormal, + )); } else if (error.error is _RemoveFailedError) { - content = L10n.global().deleteSelectedFailureNotification( - (error.error as _RemoveFailedError).count); + SnackBarManager().showSnackBar(SnackBar( + content: Text(L10n.global() + .deleteSelectedFailureNotification( + (error.error as _RemoveFailedError).count)), + duration: k.snackBarDurationNormal, + )); } else { - content = exception_util.toUserString(error.error); + SnackBarManager().showSnackBarForException(error.error); } - SnackBarManager().showSnackBar(SnackBar( - content: Text(content), - duration: k.snackBarDurationNormal, - )); } }, ), diff --git a/app/lib/widget/collection_picker.dart b/app/lib/widget/collection_picker.dart index fc4a7404..a7f46436 100644 --- a/app/lib/widget/collection_picker.dart +++ b/app/lib/widget/collection_picker.dart @@ -17,7 +17,6 @@ import 'package:nc_photos/entity/collection.dart'; import 'package:nc_photos/entity/collection/adapter.dart'; import 'package:nc_photos/entity/collection/util.dart' as collection_util; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/snack_bar_manager.dart'; @@ -99,11 +98,7 @@ class _WrappedCollectionPickerState extends State<_WrappedCollectionPicker> { listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/dir_picker.dart b/app/lib/widget/dir_picker.dart index 621323c0..85b0d595 100644 --- a/app/lib/widget/dir_picker.dart +++ b/app/lib/widget/dir_picker.dart @@ -10,7 +10,6 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:np_codegen/np_codegen.dart'; @@ -123,10 +122,7 @@ class DirPickerState extends State { try { _navigateInto(File(path: path_lib.dirname(_currentPath))); } catch (e) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } }, ); @@ -219,10 +215,7 @@ class DirPickerState extends State { try { _navigateInto(item.file); } catch (e) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } : null, @@ -238,10 +231,7 @@ class DirPickerState extends State { : "")); } } else if (state is LsDirBlocFailure) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } diff --git a/app/lib/widget/home_collections.dart b/app/lib/widget/home_collections.dart index 7770ee17..6f28fcd0 100644 --- a/app/lib/widget/home_collections.dart +++ b/app/lib/widget/home_collections.dart @@ -21,7 +21,6 @@ import 'package:nc_photos/entity/collection/content_provider/nc_album.dart'; import 'package:nc_photos/entity/collection/util.dart' as collection_util; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/platform/features.dart' as features; @@ -104,10 +103,7 @@ class _WrappedHomeCollectionsState extends State<_WrappedHomeCollections> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/home_photos2.dart b/app/lib/widget/home_photos2.dart index d9e22a20..9b8508d3 100644 --- a/app/lib/widget/home_photos2.dart +++ b/app/lib/widget/home_photos2.dart @@ -32,7 +32,6 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/event/event.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/flutter_util.dart' as flutter_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/progress_util.dart'; @@ -138,20 +137,23 @@ class _WrappedHomePhotosState extends State<_WrappedHomePhotos> { selector: (state) => state.error, listener: (context, error) { if (error != null && _isVisible == true) { - final String content; if (error.error is _ArchiveFailedError) { - content = L10n.global().archiveSelectedFailureNotification( - (error.error as _ArchiveFailedError).count); + SnackBarManager().showSnackBar(SnackBar( + content: Text(L10n.global() + .archiveSelectedFailureNotification( + (error.error as _ArchiveFailedError).count)), + duration: k.snackBarDurationNormal, + )); } else if (error.error is _RemoveFailedError) { - content = L10n.global().deleteSelectedFailureNotification( - (error.error as _RemoveFailedError).count); + SnackBarManager().showSnackBar(SnackBar( + content: Text(L10n.global() + .deleteSelectedFailureNotification( + (error.error as _RemoveFailedError).count)), + duration: k.snackBarDurationNormal, + )); } else { - content = exception_util.toUserString(error.error); + SnackBarManager().showSnackBarForException(error.error); } - SnackBarManager().showSnackBar(SnackBar( - content: Text(content), - duration: k.snackBarDurationNormal, - )); } }, ), diff --git a/app/lib/widget/home_search.dart b/app/lib/widget/home_search.dart index e4080d03..6476f6f3 100644 --- a/app/lib/widget/home_search.dart +++ b/app/lib/widget/home_search.dart @@ -14,7 +14,6 @@ import 'package:nc_photos/download_handler.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/entity/search.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/language_util.dart' as language_util; import 'package:nc_photos/object_extension.dart'; @@ -341,10 +340,7 @@ class _HomeSearchState extends State } else if (state is SearchBlocFailure) { _transformItems(state.items); if (isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } else if (state is SearchBlocInconsistent) { _reqQuery(_activeInput, _activeFilters); diff --git a/app/lib/widget/home_search_suggestion.dart b/app/lib/widget/home_search_suggestion.dart index 09a4f2cb..c0b2770e 100644 --- a/app/lib/widget/home_search_suggestion.dart +++ b/app/lib/widget/home_search_suggestion.dart @@ -8,8 +8,6 @@ import 'package:nc_photos/entity/collection.dart'; import 'package:nc_photos/entity/collection/builder.dart'; import 'package:nc_photos/entity/person.dart'; import 'package:nc_photos/entity/tag.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/list_location_group.dart'; @@ -119,10 +117,7 @@ class _HomeSearchSuggestionState extends State } else if (state is HomeSearchSuggestionBlocFailure) { _transformItems(state.results); if (isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } } diff --git a/app/lib/widget/live_photo_viewer.dart b/app/lib/widget/live_photo_viewer.dart index 4c1475df..2cf133dc 100644 --- a/app/lib/widget/live_photo_viewer.dart +++ b/app/lib/widget/live_photo_viewer.dart @@ -7,7 +7,6 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/api/api_util.dart' as api_util; import 'package:nc_photos/cache_manager_util.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/snack_bar_manager.dart'; @@ -55,10 +54,7 @@ class _LivePhotoViewerState extends State { } }).onError((e, stacktrace) { _log.shout("[initState] Failed while _getVideoUrl", e, stacktrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); widget.onLoadFailure?.call(); }); @@ -122,10 +118,7 @@ class _LivePhotoViewerState extends State { await _controller.play(); } catch (e, stackTrace) { _log.shout("[_initController] Failed while initialize", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); widget.onLoadFailure?.call(); } } diff --git a/app/lib/widget/people_browser.dart b/app/lib/widget/people_browser.dart index aef37d7a..cb3e2536 100644 --- a/app/lib/widget/people_browser.dart +++ b/app/lib/widget/people_browser.dart @@ -14,7 +14,6 @@ import 'package:nc_photos/controller/persons_controller.dart'; import 'package:nc_photos/entity/collection/builder.dart'; import 'package:nc_photos/entity/person.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/collection_browser.dart'; @@ -86,10 +85,7 @@ class _WrappedPeopleBrowserState extends State<_WrappedPeopleBrowser> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/places_browser.dart b/app/lib/widget/places_browser.dart index ed4fea99..5ea6bf42 100644 --- a/app/lib/widget/places_browser.dart +++ b/app/lib/widget/places_browser.dart @@ -13,8 +13,6 @@ import 'package:nc_photos/controller/account_controller.dart'; import 'package:nc_photos/controller/places_controller.dart'; import 'package:nc_photos/entity/collection/builder.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/list_location_group.dart'; @@ -88,10 +86,7 @@ class _WrappedPlacesBrowserState extends State<_WrappedPlacesBrowser> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/result_viewer.dart b/app/lib/widget/result_viewer.dart index 65264664..1f92f5ca 100644 --- a/app/lib/widget/result_viewer.dart +++ b/app/lib/widget/result_viewer.dart @@ -6,7 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/pref.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; @@ -112,10 +111,7 @@ class _ResultViewerState extends State { file = await LsSingleFile(_c)(_account!, filePath); } catch (e, stackTrace) { _log.severe("[_doWork] Failed while LsSingleFile", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); Navigator.of(context).pop(); return; } diff --git a/app/lib/widget/search_landing.dart b/app/lib/widget/search_landing.dart index 7a1fb696..18b2414e 100644 --- a/app/lib/widget/search_landing.dart +++ b/app/lib/widget/search_landing.dart @@ -16,7 +16,6 @@ import 'package:nc_photos/entity/collection/builder.dart'; import 'package:nc_photos/entity/person.dart'; import 'package:nc_photos/exception.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/help_utils.dart' as help_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; @@ -134,11 +133,7 @@ class _WrappedSearchLandingState extends State<_WrappedSearchLanding> { return; } } - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/account_settings.dart b/app/lib/widget/settings/account_settings.dart index 3459e9d1..2e3c8d60 100644 --- a/app/lib/widget/settings/account_settings.dart +++ b/app/lib/widget/settings/account_settings.dart @@ -14,7 +14,6 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/person.dart'; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/help_utils.dart' as help_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; @@ -129,19 +128,22 @@ class _WrappedAccountSettingsState extends State<_WrappedAccountSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - final String errorMsg; if (state.error is _AccountConflictError) { - errorMsg = - L10n.global().editAccountConflictFailureNotification; + SnackBarManager().showSnackBar(SnackBar( + content: Text( + L10n.global().editAccountConflictFailureNotification), + duration: k.snackBarDurationNormal, + )); } else if (state.error is _WritePrefError) { - errorMsg = L10n.global().writePreferenceFailureNotification; + SnackBarManager().showSnackBar(SnackBar( + content: + Text(L10n.global().writePreferenceFailureNotification), + duration: k.snackBarDurationNormal, + )); } else { - errorMsg = exception_util.toUserString(state.error!.error); + SnackBarManager() + .showSnackBarForException(state.error!.error); } - SnackBarManager().showSnackBar(SnackBar( - content: Text(errorMsg), - duration: k.snackBarDurationNormal, - )); } }, ), diff --git a/app/lib/widget/settings/collection_settings.dart b/app/lib/widget/settings/collection_settings.dart index c7b17667..0689a892 100644 --- a/app/lib/widget/settings/collection_settings.dart +++ b/app/lib/widget/settings/collection_settings.dart @@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:np_codegen/np_codegen.dart'; @@ -59,11 +57,7 @@ class _WrappedAlbumSettingsState extends State<_WrappedAlbumSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/developer_settings.dart b/app/lib/widget/settings/developer_settings.dart index 9a65bdda..4db21ef0 100644 --- a/app/lib/widget/settings/developer_settings.dart +++ b/app/lib/widget/settings/developer_settings.dart @@ -8,7 +8,6 @@ import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/cache_manager_util.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/self_signed_cert_manager.dart'; import 'package:nc_photos/snack_bar_manager.dart'; @@ -53,11 +52,7 @@ class _WrappedDeveloperSettingsState extends State<_WrappedDeveloperSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/enhancement_settings.dart b/app/lib/widget/settings/enhancement_settings.dart index 3d7a09a4..0899e278 100644 --- a/app/lib/widget/settings/enhancement_settings.dart +++ b/app/lib/widget/settings/enhancement_settings.dart @@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/size.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; @@ -69,11 +67,7 @@ class _WrappedEnhancementSettingsState listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/expert_settings.dart b/app/lib/widget/settings/expert_settings.dart index 97c199bc..4066c191 100644 --- a/app/lib/widget/settings/expert_settings.dart +++ b/app/lib/widget/settings/expert_settings.dart @@ -10,8 +10,6 @@ import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/db/entity_converter.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/pref.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:np_codegen/np_codegen.dart'; import 'package:np_db/np_db.dart'; @@ -50,10 +48,7 @@ class _WrappedExpertSettingsState extends State<_WrappedExpertSettings> { super.initState(); _errorSubscription = context.read<_Bloc>().errorStream().listen((error) { if (error.ev is _ClearCacheDatabase) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(error.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(error.error); } }); } diff --git a/app/lib/widget/settings/language_settings.dart b/app/lib/widget/settings/language_settings.dart index e365c282..fd0e1177 100644 --- a/app/lib/widget/settings/language_settings.dart +++ b/app/lib/widget/settings/language_settings.dart @@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/language_util.dart' as language_util; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; @@ -65,10 +63,7 @@ class _WrappedLanguageSettingsState extends State<_WrappedLanguageSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/metadata_settings.dart b/app/lib/widget/settings/metadata_settings.dart index 1fbad49e..3916893d 100644 --- a/app/lib/widget/settings/metadata_settings.dart +++ b/app/lib/widget/settings/metadata_settings.dart @@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/service.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; @@ -61,11 +59,7 @@ class _WrappedMetadataSettingsState extends State<_WrappedMetadataSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/misc_settings.dart b/app/lib/widget/settings/misc_settings.dart index 37d02fb7..f9201992 100644 --- a/app/lib/widget/settings/misc_settings.dart +++ b/app/lib/widget/settings/misc_settings.dart @@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/protected_page_handler.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; @@ -59,11 +57,7 @@ class _WrappedMiscSettingsState extends State<_WrappedMiscSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/photos_settings.dart b/app/lib/widget/settings/photos_settings.dart index 3bae2369..6d3d0b02 100644 --- a/app/lib/widget/settings/photos_settings.dart +++ b/app/lib/widget/settings/photos_settings.dart @@ -8,8 +8,6 @@ import 'package:nc_photos/controller/account_controller.dart'; import 'package:nc_photos/controller/account_pref_controller.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:np_codegen/np_codegen.dart'; @@ -63,11 +61,7 @@ class _WrappedPhotosSettingsState extends State<_WrappedPhotosSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/theme_settings.dart b/app/lib/widget/settings/theme_settings.dart index b691dd62..62145178 100644 --- a/app/lib/widget/settings/theme_settings.dart +++ b/app/lib/widget/settings/theme_settings.dart @@ -9,8 +9,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/android/android_info.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/session_storage.dart'; @@ -65,11 +63,7 @@ class _WrappedThemeSettingsState extends State<_WrappedThemeSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/settings/viewer_settings.dart b/app/lib/widget/settings/viewer_settings.dart index ffe50e82..7199333b 100644 --- a/app/lib/widget/settings/viewer_settings.dart +++ b/app/lib/widget/settings/viewer_settings.dart @@ -6,9 +6,7 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc_util.dart'; import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/gps_map_util.dart'; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:np_codegen/np_codegen.dart'; @@ -64,11 +62,7 @@ class _WrappedViewerSettingsState extends State<_WrappedViewerSettings> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: - Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/shared_file_viewer.dart b/app/lib/widget/shared_file_viewer.dart index 290607f9..6faaa836 100644 --- a/app/lib/widget/shared_file_viewer.dart +++ b/app/lib/widget/shared_file_viewer.dart @@ -14,7 +14,6 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/share/data_source.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; @@ -240,10 +239,7 @@ class _SharedFileViewerState extends State { } catch (e, stackTrace) { _log.shout( "[_onItemUnsharePressed] Failed while RemoveShare", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); } } diff --git a/app/lib/widget/sharing_browser.dart b/app/lib/widget/sharing_browser.dart index 88c5c080..4019881f 100644 --- a/app/lib/widget/sharing_browser.dart +++ b/app/lib/widget/sharing_browser.dart @@ -22,8 +22,6 @@ import 'package:nc_photos/entity/file/data_source.dart'; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/import_potential_shared_album.dart'; @@ -112,10 +110,7 @@ class _WrappedSharingBrowserState extends State<_WrappedSharingBrowser> listenWhen: (previous, current) => previous.error != current.error, listener: (context, state) { if (state.error != null && isPageVisible()) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.error!.error)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.error!.error); } }, ), diff --git a/app/lib/widget/tag_picker_dialog.dart b/app/lib/widget/tag_picker_dialog.dart index bc754e85..e66615c1 100644 --- a/app/lib/widget/tag_picker_dialog.dart +++ b/app/lib/widget/tag_picker_dialog.dart @@ -6,7 +6,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/bloc/list_tag.dart'; import 'package:nc_photos/bloc/search_suggestion.dart'; import 'package:nc_photos/entity/tag.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/dialog_scaffold.dart'; @@ -109,10 +108,7 @@ class _TagPickerDialogState extends State { if (state is ListTagBlocSuccess) { _transformSuggestionItems(state.items); } else if (state is ListTagBlocFailure) { - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } } diff --git a/app/lib/widget/trashbin_browser.dart b/app/lib/widget/trashbin_browser.dart index 2ca28a0f..66bf053e 100644 --- a/app/lib/widget/trashbin_browser.dart +++ b/app/lib/widget/trashbin_browser.dart @@ -14,7 +14,6 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/pref.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/language_util.dart' as language_util; import 'package:nc_photos/object_extension.dart'; @@ -258,10 +257,7 @@ class _TrashbinBrowserState extends State _transformItems(state.items); } else if (state is LsTrashbinBlocFailure) { _transformItems(state.items); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(state.exception)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(state.exception); } else if (state is LsTrashbinBlocInconsistent) { _reqQuery(); } diff --git a/app/lib/widget/video_viewer.dart b/app/lib/widget/video_viewer.dart index 6ae10867..dff1d8ce 100644 --- a/app/lib/widget/video_viewer.dart +++ b/app/lib/widget/video_viewer.dart @@ -9,7 +9,6 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/pref.dart'; -import 'package:nc_photos/exception_util.dart' as exception_util; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/snack_bar_manager.dart'; @@ -69,10 +68,7 @@ class _VideoViewerState extends State } }).onError((e, stacktrace) { _log.shout("[initState] Failed while _getVideoUrl", e, stacktrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); widget.onLoadFailure?.call(); }); } @@ -135,10 +131,7 @@ class _VideoViewerState extends State }); } catch (e, stackTrace) { _log.shout("[_initController] Failed while initialize", e, stackTrace); - SnackBarManager().showSnackBar(SnackBar( - content: Text(exception_util.toUserString(e)), - duration: k.snackBarDurationNormal, - )); + SnackBarManager().showSnackBarForException(e); widget.onLoadFailure?.call(); } }