2021-06-28 18:25:35 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2020-07-07 21:46:14 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-06-28 18:25:35 +00:00
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
2020-07-07 21:46:14 +00:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2022-06-10 14:33:43 +00:00
|
|
|
import 'package:photos/ente_theme_data.dart';
|
2020-07-07 21:46:14 +00:00
|
|
|
|
2022-09-21 03:52:31 +00:00
|
|
|
Future showToast(
|
2022-06-10 14:29:56 +00:00
|
|
|
BuildContext context,
|
|
|
|
String message, {
|
|
|
|
toastLength = Toast.LENGTH_LONG,
|
2022-09-12 09:51:07 +00:00
|
|
|
iOSDismissOnTap = true,
|
2022-06-10 14:29:56 +00:00
|
|
|
}) async {
|
2021-06-28 18:25:35 +00:00
|
|
|
if (Platform.isAndroid) {
|
2021-08-04 17:33:59 +00:00
|
|
|
await Fluttertoast.cancel();
|
2021-06-28 18:25:35 +00:00
|
|
|
return Fluttertoast.showToast(
|
2022-06-11 08:23:52 +00:00
|
|
|
msg: message,
|
|
|
|
toastLength: toastLength,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
timeInSecForIosWeb: 1,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.toastBackgroundColor,
|
|
|
|
textColor: Theme.of(context).colorScheme.toastTextColor,
|
|
|
|
fontSize: 16.0,
|
|
|
|
);
|
2021-06-28 18:25:35 +00:00
|
|
|
} else {
|
|
|
|
EasyLoading.instance
|
2022-06-10 14:33:43 +00:00
|
|
|
..backgroundColor = Theme.of(context).colorScheme.toastBackgroundColor
|
|
|
|
..indicatorColor = Theme.of(context).colorScheme.toastBackgroundColor
|
|
|
|
..textColor = Theme.of(context).colorScheme.toastTextColor
|
2021-06-29 05:51:28 +00:00
|
|
|
..userInteractions = true
|
2021-06-28 18:25:35 +00:00
|
|
|
..loadingStyle = EasyLoadingStyle.custom;
|
|
|
|
return EasyLoading.showToast(
|
|
|
|
message,
|
2023-01-05 08:43:16 +00:00
|
|
|
duration: Duration(seconds: (toastLength == Toast.LENGTH_LONG ? 5 : 1)),
|
2021-06-28 18:25:35 +00:00
|
|
|
toastPosition: EasyLoadingToastPosition.bottom,
|
2022-09-12 09:51:07 +00:00
|
|
|
dismissOnTap: iOSDismissOnTap,
|
2021-06-28 18:25:35 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-07 21:46:14 +00:00
|
|
|
}
|
2021-10-29 22:18:24 +00:00
|
|
|
|
2022-06-10 14:29:56 +00:00
|
|
|
Future<void> showShortToast(context, String message) {
|
|
|
|
return showToast(context, message, toastLength: Toast.LENGTH_SHORT);
|
2021-10-29 22:18:24 +00:00
|
|
|
}
|