ente/lib/utils/toast_util.dart

46 lines
1.4 KiB
Dart
Raw Normal View History

// @dart=2.9
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';
import 'package:photos/ente_theme_data.dart';
2020-07-07 21:46:14 +00:00
2022-06-10 14:29:56 +00:00
Future<void> showToast(
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) {
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
..backgroundColor = Theme.of(context).colorScheme.toastBackgroundColor
..indicatorColor = Theme.of(context).colorScheme.toastBackgroundColor
..textColor = Theme.of(context).colorScheme.toastTextColor
..userInteractions = true
2021-06-28 18:25:35 +00:00
..loadingStyle = EasyLoadingStyle.custom;
return EasyLoading.showToast(
message,
2021-10-29 22:18:24 +00:00
duration: Duration(seconds: (toastLength == Toast.LENGTH_LONG ? 5 : 2)),
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
}