Pass context to toast_util

This commit is contained in:
vishnukvmd 2022-06-10 19:59:56 +05:30
parent 78bcc86912
commit 2ecd872f3d
28 changed files with 87 additions and 74 deletions

View file

@ -210,7 +210,7 @@ class UserService {
); );
await dialog.hide(); await dialog.hide();
if (response != null && response.statusCode == 200) { if (response != null && response.statusCode == 200) {
showShortToast("Email verification successful!"); showShortToast(context, "Email verification successful!");
Widget page; Widget page;
final String twoFASessionID = response.data["twoFactorSessionID"]; final String twoFASessionID = response.data["twoFactorSessionID"];
if (twoFASessionID != null && twoFASessionID.isNotEmpty) { if (twoFASessionID != null && twoFASessionID.isNotEmpty) {
@ -275,7 +275,7 @@ class UserService {
); );
await dialog.hide(); await dialog.hide();
if (response != null && response.statusCode == 200) { if (response != null && response.statusCode == 200) {
showToast("Email changed to " + email); showToast(context, "Email changed to " + email);
_config.setEmail(email); _config.setEmail(email);
Navigator.of(context).popUntil((route) => route.isFirst); Navigator.of(context).popUntil((route) => route.isFirst);
Bus.instance.fire(UserDetailsChangedEvent()); Bus.instance.fire(UserDetailsChangedEvent());
@ -384,7 +384,7 @@ class UserService {
); );
await dialog.hide(); await dialog.hide();
if (response != null && response.statusCode == 200) { if (response != null && response.statusCode == 200) {
showToast("Authentication successful!"); showToast(context, "Authentication successful!");
await _saveConfiguration(response); await _saveConfiguration(response);
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
@ -399,7 +399,7 @@ class UserService {
await dialog.hide(); await dialog.hide();
_logger.severe(e); _logger.severe(e);
if (e.response != null && e.response.statusCode == 404) { if (e.response != null && e.response.statusCode == 404) {
showToast("Session expired"); showToast(context, "Session expired");
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
@ -446,7 +446,7 @@ class UserService {
} on DioError catch (e) { } on DioError catch (e) {
_logger.severe(e); _logger.severe(e);
if (e.response != null && e.response.statusCode == 404) { if (e.response != null && e.response.statusCode == 404) {
showToast("Session expired"); showToast(context, "Session expired");
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
@ -498,7 +498,7 @@ class UserService {
}, },
); );
if (response != null && response.statusCode == 200) { if (response != null && response.statusCode == 200) {
showShortToast("Two-factor authentication successfully reset"); showShortToast(context, "Two-factor authentication successfully reset");
await _saveConfiguration(response); await _saveConfiguration(response);
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
@ -512,7 +512,7 @@ class UserService {
} on DioError catch (e) { } on DioError catch (e) {
_logger.severe(e); _logger.severe(e);
if (e.response != null && e.response.statusCode == 404) { if (e.response != null && e.response.statusCode == 404) {
showToast("Session expired"); showToast(context, "Session expired");
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
@ -622,7 +622,7 @@ class UserService {
); );
Bus.instance.fire(TwoFactorStatusChangeEvent(false)); Bus.instance.fire(TwoFactorStatusChangeEvent(false));
await dialog.hide(); await dialog.hide();
showToast("Two-factor authentication has been disabled"); showToast(context, "Two-factor authentication has been disabled");
} catch (e, s) { } catch (e, s) {
await dialog.hide(); await dialog.hide();
_logger.severe(e, s); _logger.severe(e, s);

View file

@ -486,7 +486,7 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
), ),
), ),
onTap: () async { onTap: () async {
await showToast( await showToast(context,
"long press to select photos and click + to create an album", "long press to select photos and click + to create an album",
toastLength: Toast.LENGTH_LONG); toastLength: Toast.LENGTH_LONG);
Bus.instance Bus.instance

View file

@ -181,7 +181,9 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
), ),
onTap: () async { onTap: () async {
if (await _runCollectionAction(item.collection.id)) { if (await _runCollectionAction(item.collection.id)) {
showShortToast(widget.actionType == CollectionActionType.addFiles showShortToast(
context,
widget.actionType == CollectionActionType.addFiles
? "Added successfully to " + item.collection.name ? "Added successfully to " + item.collection.name
: "Moved successfully to " + item.collection.name); : "Moved successfully to " + item.collection.name);
_navigateToCollection(item.collection); _navigateToCollection(item.collection);
@ -240,9 +242,11 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
if (collection != null) { if (collection != null) {
if (await _runCollectionAction(collection.id)) { if (await _runCollectionAction(collection.id)) {
if (widget.actionType == CollectionActionType.restoreFiles) { if (widget.actionType == CollectionActionType.restoreFiles) {
showShortToast('Restored files to album ' + _albumName); showShortToast(
context, 'Restored files to album ' + _albumName);
} else { } else {
showShortToast("Album '" + _albumName + "' created."); showShortToast(
context, "Album '" + _albumName + "' created.");
} }
_navigateToCollection(collection); _navigateToCollection(collection);
} }

View file

@ -64,7 +64,7 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
_duplicates = _duplicates =
DeduplicationService.instance.clubDuplicatesByTime(widget.duplicates); DeduplicationService.instance.clubDuplicatesByTime(widget.duplicates);
_selectAllFilesButFirst(); _selectAllFilesButFirst();
showToast("Long-press on an item to view in full-screen"); showToast(context, "Long-press on an item to view in full-screen");
} }
void _selectAllFilesButFirst() { void _selectAllFilesButFirst() {

View file

@ -219,7 +219,7 @@ class FadingAppBarState extends State<FadingAppBar> {
} catch (e, s) { } catch (e, s) {
_logger.severe(e, s); _logger.severe(e, s);
hasError = true; hasError = true;
showToast("Sorry, could not add this to favorites!"); showToast(context, "Sorry, could not add this to favorites!");
} finally { } finally {
if (shouldBlockUser) { if (shouldBlockUser) {
await dialog.hide(); await dialog.hide();
@ -231,7 +231,7 @@ class FadingAppBarState extends State<FadingAppBar> {
} catch (e, s) { } catch (e, s) {
_logger.severe(e, s); _logger.severe(e, s);
hasError = true; hasError = true;
showToast("Sorry, could not remove this from favorites!"); showToast(context, "Sorry, could not remove this from favorites!");
} }
} }
return hasError ? oldValue : isLiked; return hasError ? oldValue : isLiked;
@ -294,7 +294,7 @@ class FadingAppBarState extends State<FadingAppBar> {
isDestructiveAction: true, isDestructiveAction: true,
onPressed: () async { onPressed: () async {
await deleteFilesOnDeviceOnly(context, [file]); await deleteFilesOnDeviceOnly(context, [file]);
showToast("File deleted from device"); showToast(context, "File deleted from device");
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
// TODO: Fix behavior when inside a device folder // TODO: Fix behavior when inside a device folder
}, },
@ -305,7 +305,7 @@ class FadingAppBarState extends State<FadingAppBar> {
isDestructiveAction: true, isDestructiveAction: true,
onPressed: () async { onPressed: () async {
await deleteFilesFromRemoteOnly(context, [file]); await deleteFilesFromRemoteOnly(context, [file]);
showShortToast("Moved to trash"); showShortToast(context, "Moved to trash");
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
// TODO: Fix behavior when inside a collection // TODO: Fix behavior when inside a collection
}, },
@ -364,9 +364,9 @@ class FadingAppBarState extends State<FadingAppBar> {
Bus.instance.fire(LocalPhotosUpdatedEvent([file])); Bus.instance.fire(LocalPhotosUpdatedEvent([file]));
await dialog.hide(); await dialog.hide();
if (file.fileType == FileType.livePhoto) { if (file.fileType == FileType.livePhoto) {
showToast("Photo and video saved to gallery"); showToast(context, "Photo and video saved to gallery");
} else { } else {
showToast("File saved to gallery"); showToast(context, "File saved to gallery");
} }
} }
} }

View file

@ -275,7 +275,7 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
], ],
), ),
onPressed: () { onPressed: () {
showShortToast("This image has no exif data"); showShortToast(context, "This image has no exif data");
}, },
), ),
); );

View file

@ -448,7 +448,7 @@ class _OverlayWidgetState extends State<OverlayWidget> {
await deleteFilesOnDeviceOnly( await deleteFilesOnDeviceOnly(
context, widget.selectedFiles.files.toList()); context, widget.selectedFiles.files.toList());
_clearSelectedFiles(); _clearSelectedFiles();
showToast("Files deleted from device"); showToast(context, "Files deleted from device");
}, },
)); ));
actions.add(CupertinoActionSheetAction( actions.add(CupertinoActionSheetAction(
@ -459,7 +459,7 @@ class _OverlayWidgetState extends State<OverlayWidget> {
await deleteFilesFromRemoteOnly( await deleteFilesFromRemoteOnly(
context, widget.selectedFiles.files.toList()); context, widget.selectedFiles.files.toList());
_clearSelectedFiles(); _clearSelectedFiles();
showShortToast("Moved to trash"); showShortToast(context, "Moved to trash");
}, },
)); ));
actions.add(CupertinoActionSheetAction( actions.add(CupertinoActionSheetAction(

View file

@ -300,7 +300,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
if (img == null) { if (img == null) {
_logger.severe("null rawImageData"); _logger.severe("null rawImageData");
showToast("Something went wrong"); showToast(context, "Something went wrong");
return; return;
} }
@ -329,7 +329,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
if (result == null) { if (result == null) {
_logger.severe("null result"); _logger.severe("null result");
showToast("Something went wrong"); showToast(context, "Something went wrong");
return; return;
} }
try { try {
@ -358,7 +358,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
await LocalSyncService.instance.trackEditedFile(newFile); await LocalSyncService.instance.trackEditedFile(newFile);
Bus.instance.fire(LocalPhotosUpdatedEvent([newFile])); Bus.instance.fire(LocalPhotosUpdatedEvent([newFile]));
SyncService.instance.sync(); SyncService.instance.sync();
showToast("Edits saved"); showToast(context, "Edits saved");
_logger.info("Original file " + widget.originalFile.toString()); _logger.info("Original file " + widget.originalFile.toString());
_logger.info("Saved edits to file " + newFile.toString()); _logger.info("Saved edits to file " + newFile.toString());
final existingFiles = widget.detailPageConfig.files; final existingFiles = widget.detailPageConfig.files;
@ -377,7 +377,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
), ),
); );
} catch (e, s) { } catch (e, s) {
showToast("Oops, could not save edits"); showToast(context, "Oops, could not save edits");
_logger.severe(e, s); _logger.severe(e, s);
} }
await dialog.hide(); await dialog.hide();

View file

@ -414,7 +414,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
try { try {
await CollectionsService.instance.updateShareUrl(widget.collection, prop); await CollectionsService.instance.updateShareUrl(widget.collection, prop);
await dialog.hide(); await dialog.hide();
showToast("Album updated"); showToast(context, "Album updated");
} catch (e) { } catch (e) {
await dialog.hide(); await dialog.hide();
await showGenericErrorDialog(context); await showGenericErrorDialog(context);

View file

@ -429,7 +429,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
.updatePassword(_passwordController1.text); .updatePassword(_passwordController1.text);
await UserService.instance.updateKeyAttributes(keyAttributes); await UserService.instance.updateKeyAttributes(keyAttributes);
await dialog.hide(); await dialog.hide();
showShortToast("Password changed successfully"); showShortToast(context, "Password changed successfully");
Navigator.of(context).pop(); Navigator.of(context).pop();
if (widget.mode == PasswordEntryMode.reset) { if (widget.mode == PasswordEntryMode.reset) {
Bus.instance.fire(SubscriptionPurchasedEvent()); Bus.instance.fire(SubscriptionPurchasedEvent());

View file

@ -94,7 +94,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
try { try {
await _fetchSub(); await _fetchSub();
} catch (e) { } catch (e) {
showToast("Failed to refresh subscription"); showToast(context, "Failed to refresh subscription");
} }
await _dialog.hide(); await _dialog.hide();
@ -383,7 +383,8 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
: await _billingService.cancelStripeSubscription(); : await _billingService.cancelStripeSubscription();
await _fetchSub(); await _fetchSub();
} catch (e) { } catch (e) {
showToast(isRenewCancelled ? 'failed to renew' : 'failed to cancel'); showToast(
context, isRenewCancelled ? 'failed to renew' : 'failed to cancel');
} }
await _dialog.hide(); await _dialog.hide();
} }

View file

@ -86,7 +86,7 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
text = "your plan was successfully downgraded"; text = "your plan was successfully downgraded";
} }
} }
showToast(text); showToast(context, text);
_currentSubscription = newSubscription; _currentSubscription = newSubscription;
_hasActiveSubscription = _currentSubscription.isValid(); _hasActiveSubscription = _currentSubscription.isValid();
setState(() {}); setState(() {});

View file

@ -117,7 +117,7 @@ class _RecoveryKeyPageState extends State<RecoveryKeyPage> {
onTap: () async { onTap: () async {
await Clipboard.setData( await Clipboard.setData(
ClipboardData(text: recoveryKey)); ClipboardData(text: recoveryKey));
showToast("Recovery key copied to clipboard"); showToast(context, "Recovery key copied to clipboard");
setState(() { setState(() {
_hasTriedToSave = true; _hasTriedToSave = true;
}); });

View file

@ -40,7 +40,7 @@ class _RecoveryPageState extends State<RecoveryPage> {
try { try {
await Configuration.instance.recover(_recoveryKey.text.trim()); await Configuration.instance.recover(_recoveryKey.text.trim());
await dialog.hide(); await dialog.hide();
showToast("Recovery successful!"); showToast(context, "Recovery successful!");
Navigator.of(context).pushReplacement( Navigator.of(context).pushReplacement(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {

View file

@ -128,7 +128,7 @@ class _SessionsPageState extends State<SessionsPage> {
_sessions = await UserService.instance _sessions = await UserService.instance
.getActiveSessions() .getActiveSessions()
.onError((error, stackTrace) { .onError((error, stackTrace) {
showToast("Failed to fetch active sessions"); showToast(context, "Failed to fetch active sessions");
throw error; throw error;
}); });
_sessions.sessions.sort((first, second) { _sessions.sessions.sort((first, second) {

View file

@ -75,11 +75,11 @@ class _SetWallpaperDialogState extends State<SetWallpaperDialog> {
await WallpaperManagerFlutter().setwallpaperfromFile( await WallpaperManagerFlutter().setwallpaperfromFile(
await getFile(widget.file), _lockscreenValue); await getFile(widget.file), _lockscreenValue);
await dialog.hide(); await dialog.hide();
showToast("Wallpaper set successfully"); showToast(context, "Wallpaper set successfully");
} catch (e, s) { } catch (e, s) {
await dialog.hide(); await dialog.hide();
Logger("SetWallpaperDialog").severe(e, s); Logger("SetWallpaperDialog").severe(e, s);
showToast("Something went wrong"); showToast(context, "Something went wrong");
return; return;
} }
}, },

View file

@ -62,7 +62,7 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
AppLock.of(context) AppLock.of(context)
.setEnabled(Configuration.instance.shouldShowLockScreen()); .setEnabled(Configuration.instance.shouldShowLockScreen());
if (!result) { if (!result) {
showToast(reason); showToast(context, reason);
return; return;
} }
@ -91,7 +91,7 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
AppLock.of(context) AppLock.of(context)
.setEnabled(Configuration.instance.shouldShowLockScreen()); .setEnabled(Configuration.instance.shouldShowLockScreen());
if (!result) { if (!result) {
showToast(reason); showToast(context, reason);
return; return;
} }
showDialog( showDialog(
@ -116,7 +116,7 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
AppLock.of(context) AppLock.of(context)
.setEnabled(Configuration.instance.shouldShowLockScreen()); .setEnabled(Configuration.instance.shouldShowLockScreen());
if (!result) { if (!result) {
showToast(reason); showToast(context, reason);
return; return;
} }
Navigator.of(context).push( Navigator.of(context).push(

View file

@ -194,7 +194,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
), ),
onPressed: () { onPressed: () {
if (Platform.isIOS) { if (Platform.isIOS) {
showToast( showToast(context,
"Also empty \"Recently Deleted\" from \"Settings\" -> \"Storage\" to claim the freed space"); "Also empty \"Recently Deleted\" from \"Settings\" -> \"Storage\" to claim the freed space");
} }
Navigator.of(context, rootNavigator: true).pop('dialog'); Navigator.of(context, rootNavigator: true).pop('dialog');
@ -251,7 +251,8 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
), ),
), ),
onPressed: () { onPressed: () {
showToast("Also empty your \"Trash\" to claim the freed up space"); showToast(context,
"Also empty your \"Trash\" to claim the freed up space");
Navigator.of(context, rootNavigator: true).pop('dialog'); Navigator.of(context, rootNavigator: true).pop('dialog');
}, },
), ),

View file

@ -99,7 +99,7 @@ class InfoSectionWidget extends StatelessWidget {
barrierColor: Colors.black.withOpacity(0.85), barrierColor: Colors.black.withOpacity(0.85),
); );
} else { } else {
showToast("You are on the latest version"); showToast(context, "You are on the latest version");
} }
}, },
child: SettingsTextItem( child: SettingsTextItem(

View file

@ -89,7 +89,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
AppLock.of(context).setEnabled( AppLock.of(context).setEnabled(
Configuration.instance.shouldShowLockScreen()); Configuration.instance.shouldShowLockScreen());
if (!result) { if (!result) {
showToast(reason); showToast(context, reason);
return; return;
} }
if (value) { if (value) {
@ -248,7 +248,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
AppLock.of(context) AppLock.of(context)
.setEnabled(Configuration.instance.shouldShowLockScreen()); .setEnabled(Configuration.instance.shouldShowLockScreen());
if (!result) { if (!result) {
showToast(kAuthToViewSessions); showToast(context, kAuthToViewSessions);
return; return;
} }
Navigator.of(context).push( Navigator.of(context).push(

View file

@ -254,7 +254,7 @@ class _SharingDialogState extends State<SharingDialog> {
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
await Clipboard.setData(ClipboardData(text: url)); await Clipboard.setData(ClipboardData(text: url));
showToast("Link copied to clipboard"); showToast(context, "Link copied to clipboard");
}, },
child: Container( child: Container(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
@ -406,7 +406,7 @@ class _SharingDialogState extends State<SharingDialog> {
await CollectionsService.instance await CollectionsService.instance
.share(widget.collection.id, email, publicKey); .share(widget.collection.id, email, publicKey);
await dialog.hide(); await dialog.hide();
showShortToast("Shared successfully!"); showShortToast(context, "Shared successfully!");
setState(() { setState(() {
_sharees.add(User(email: email)); _sharees.add(User(email: email));
_showEntryField = false; _showEntryField = false;
@ -502,7 +502,7 @@ class EmailItemWidget extends StatelessWidget {
await CollectionsService.instance.unshare(collection.id, email); await CollectionsService.instance.unshare(collection.id, email);
collection.sharees.removeWhere((user) => user.email == email); collection.sharees.removeWhere((user) => user.email == email);
await dialog.hide(); await dialog.hide();
showToast("Stopped sharing with " + email + "."); showToast(context, "Stopped sharing with " + email + ".");
Navigator.of(context).pop(); Navigator.of(context).pop();
} catch (e, s) { } catch (e, s) {
Logger("EmailItemWidget").severe(e, s); Logger("EmailItemWidget").severe(e, s);

View file

@ -239,7 +239,7 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
Color(0xFF1DB954), Color(0xFF1DB954),
], ],
onTap: () async { onTap: () async {
await showToast("Select an album on ente to share", await showToast(context, "Select an album on ente to share",
toastLength: Toast.LENGTH_LONG); toastLength: Toast.LENGTH_LONG);
Bus.instance.fire( Bus.instance.fire(
TabChangedEvent(1, TabChangedEventSource.collections_page)); TabChangedEvent(1, TabChangedEventSource.collections_page));

View file

@ -129,7 +129,7 @@ class _TwoFactorSetupPageState extends State<TwoFactorSetupPage>
return GestureDetector( return GestureDetector(
onTap: () async { onTap: () async {
await Clipboard.setData(ClipboardData(text: widget.secretCode)); await Clipboard.setData(ClipboardData(text: widget.secretCode));
showToast("Code copied to clipboard"); showToast(context, "Code copied to clipboard");
}, },
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,

View file

@ -75,7 +75,7 @@ class _VideoWidgetState extends State<VideoWidget> {
setState(() { setState(() {
_progress = count / total; _progress = count / total;
if (_progress == 1) { if (_progress == 1) {
showShortToast("decrypting video..."); showShortToast(context, "Decrypting video...");
} }
}); });
} }

View file

@ -115,7 +115,7 @@ class _ZoomableLiveImageState extends State<ZoomableLiveImage>
} }
_isLoadingVideoPlayer = true; _isLoadingVideoPlayer = true;
if (_file.isRemoteFile() && !(await isFileCached(_file, liveVideo: true))) { if (_file.isRemoteFile() && !(await isFileCached(_file, liveVideo: true))) {
showToast("Downloading...", toastLength: Toast.LENGTH_LONG); showToast(context, "Downloading...", toastLength: Toast.LENGTH_LONG);
} }
var videoFile = await getFile(widget.file, liveVideo: true) var videoFile = await getFile(widget.file, liveVideo: true)
@ -138,7 +138,7 @@ class _ZoomableLiveImageState extends State<ZoomableLiveImage>
if (videoFile != null && videoFile.existsSync()) { if (videoFile != null && videoFile.existsSync()) {
_setVideoPlayerController(file: videoFile); _setVideoPlayerController(file: videoFile);
} else { } else {
showShortToast("download failed"); showShortToast(context, "download failed");
} }
_isLoadingVideoPlayer = false; _isLoadingVideoPlayer = false;
} }
@ -159,7 +159,7 @@ class _ZoomableLiveImageState extends State<ZoomableLiveImage>
var _preferences = await SharedPreferences.getInstance(); var _preferences = await SharedPreferences.getInstance();
int promptTillNow = _preferences.getInt(kLivePhotoToastCounterKey) ?? 0; int promptTillNow = _preferences.getInt(kLivePhotoToastCounterKey) ?? 0;
if (promptTillNow < kMaxLivePhotoToastCount) { if (promptTillNow < kMaxLivePhotoToastCount) {
showToast("Press and hold to play video"); showToast(context, "Press and hold to play video");
_preferences.setInt(kLivePhotoToastCounterKey, promptTillNow + 1); _preferences.setInt(kLivePhotoToastCounterKey, promptTillNow + 1);
} }
} }

View file

@ -119,9 +119,9 @@ Future<void> deleteFilesFromEverywhere(
Bus.instance.fire(LocalPhotosUpdatedEvent(deletedFiles, Bus.instance.fire(LocalPhotosUpdatedEvent(deletedFiles,
type: EventType.deletedFromEverywhere)); type: EventType.deletedFromEverywhere));
if (hasLocalOnlyFiles && Platform.isAndroid) { if (hasLocalOnlyFiles && Platform.isAndroid) {
showShortToast("Files deleted"); showShortToast(context, "Files deleted");
} else { } else {
showShortToast("Moved to trash"); showShortToast(context, "Moved to trash");
} }
} }
await dialog.hide(); await dialog.hide();
@ -134,7 +134,7 @@ Future<void> deleteFilesFromRemoteOnly(
BuildContext context, List<File> files) async { BuildContext context, List<File> files) async {
files.removeWhere((element) => element.uploadedFileID == null); files.removeWhere((element) => element.uploadedFileID == null);
if (files.isEmpty) { if (files.isEmpty) {
showToast("Selected files are not on ente"); showToast(context, "Selected files are not on ente");
return; return;
} }
final dialog = createProgressDialog(context, "Deleting..."); final dialog = createProgressDialog(context, "Deleting...");
@ -239,7 +239,7 @@ Future<bool> deleteFromTrash(BuildContext context, List<File> files) async {
await dialog.show(); await dialog.show();
try { try {
await TrashSyncService.instance.deleteFromTrash(files); await TrashSyncService.instance.deleteFromTrash(files);
showShortToast("Successfully deleted"); showShortToast(context, "Successfully deleted");
await dialog.hide(); await dialog.hide();
Bus.instance Bus.instance
.fire(FilesUpdatedEvent(files, type: EventType.deletedFromEverywhere)); .fire(FilesUpdatedEvent(files, type: EventType.deletedFromEverywhere));
@ -263,7 +263,7 @@ Future<bool> emptyTrash(BuildContext context) async {
await dialog.show(); await dialog.show();
try { try {
await TrashSyncService.instance.emptyTrash(); await TrashSyncService.instance.emptyTrash();
showShortToast("Trash emptied"); showShortToast(context, "Trash emptied");
await dialog.hide(); await dialog.hide();
return true; return true;
} catch (e, s) { } catch (e, s) {
@ -307,7 +307,7 @@ Future<bool> deleteLocalFiles(
Bus.instance.fire(LocalPhotosUpdatedEvent(deletedFiles)); Bus.instance.fire(LocalPhotosUpdatedEvent(deletedFiles));
return true; return true;
} else { } else {
showToast("Could not free up space"); showToast(context, "Could not free up space");
return false; return false;
} }
} }

View file

@ -22,7 +22,9 @@ Future<void> changeVisibility(
await dialog.show(); await dialog.show();
try { try {
await FileMagicService.instance.changeVisibility(files, newVisibility); await FileMagicService.instance.changeVisibility(files, newVisibility);
showShortToast(newVisibility == kVisibilityArchive showShortToast(
context,
newVisibility == kVisibilityArchive
? "Successfully hidden" ? "Successfully hidden"
: "Successfully unhidden"); : "Successfully unhidden");
@ -44,7 +46,9 @@ Future<void> changeCollectionVisibility(
await CollectionsService.instance.updateMagicMetadata(collection, update); await CollectionsService.instance.updateMagicMetadata(collection, update);
// Force reload home gallery to pull in the now unarchived files // Force reload home gallery to pull in the now unarchived files
Bus.instance.fire(ForceReloadHomeGalleryEvent()); Bus.instance.fire(ForceReloadHomeGalleryEvent());
showShortToast(newVisibility == kVisibilityArchive showShortToast(
context,
newVisibility == kVisibilityArchive
? "Successfully hidden" ? "Successfully hidden"
: "Successfully unhidden"); : "Successfully unhidden");
@ -63,7 +67,7 @@ Future<bool> editTime(
context, files, kPubMagicKeyEditedTime, editedTime); context, files, kPubMagicKeyEditedTime, editedTime);
return true; return true;
} catch (e, s) { } catch (e, s) {
showToast('something went wrong'); showToast(context, 'something went wrong');
return false; return false;
} }
} }
@ -92,7 +96,7 @@ Future<bool> editFilename(
context, List.of([file]), kPubMagicKeyEditedName, result); context, List.of([file]), kPubMagicKeyEditedName, result);
return true; return true;
} catch (e, s) { } catch (e, s) {
showToast('something went wrong'); showToast(context, 'something went wrong');
return false; return false;
} }
} }
@ -107,7 +111,7 @@ Future<void> _updatePublicMetadata(
try { try {
Map<String, dynamic> update = {key: value}; Map<String, dynamic> update = {key: value};
await FileMagicService.instance.updatePublicMagicMetadata(files, update); await FileMagicService.instance.updatePublicMagicMetadata(files, update);
showShortToast('done'); showShortToast(context, 'done');
await dialog.hide(); await dialog.hide();
if (_shouldReloadGallery(key)) { if (_shouldReloadGallery(key)) {
Bus.instance.fire(ForceReloadHomeGalleryEvent()); Bus.instance.fire(ForceReloadHomeGalleryEvent());

View file

@ -4,8 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
Future<void> showToast(String message, Future<void> showToast(
{toastLength = Toast.LENGTH_LONG}) async { BuildContext context,
String message, {
toastLength = Toast.LENGTH_LONG,
}) async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
await Fluttertoast.cancel(); await Fluttertoast.cancel();
return Fluttertoast.showToast( return Fluttertoast.showToast(
@ -31,6 +34,6 @@ Future<void> showToast(String message,
} }
} }
Future<void> showShortToast(String message) { Future<void> showShortToast(context, String message) {
return showToast(message, toastLength: Toast.LENGTH_SHORT); return showToast(context, message, toastLength: Toast.LENGTH_SHORT);
} }