toast_util.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyloading/flutter_easyloading.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:photos/ente_theme_data.dart';
  6. Future showToast(
  7. BuildContext context,
  8. String message, {
  9. toastLength = Toast.LENGTH_LONG,
  10. iOSDismissOnTap = true,
  11. }) async {
  12. if (Platform.isAndroid) {
  13. await Fluttertoast.cancel();
  14. return Fluttertoast.showToast(
  15. msg: message,
  16. toastLength: toastLength,
  17. gravity: ToastGravity.BOTTOM,
  18. timeInSecForIosWeb: 1,
  19. backgroundColor: Theme.of(context).colorScheme.toastBackgroundColor,
  20. textColor: Theme.of(context).colorScheme.toastTextColor,
  21. fontSize: 16.0,
  22. );
  23. } else {
  24. EasyLoading.instance
  25. ..backgroundColor = Theme.of(context).colorScheme.toastBackgroundColor
  26. ..indicatorColor = Theme.of(context).colorScheme.toastBackgroundColor
  27. ..textColor = Theme.of(context).colorScheme.toastTextColor
  28. ..userInteractions = true
  29. ..loadingStyle = EasyLoadingStyle.custom;
  30. return EasyLoading.showToast(
  31. message,
  32. duration: Duration(seconds: (toastLength == Toast.LENGTH_LONG ? 5 : 1)),
  33. toastPosition: EasyLoadingToastPosition.bottom,
  34. dismissOnTap: iOSDismissOnTap,
  35. );
  36. }
  37. }
  38. Future<void> showShortToast(context, String message) {
  39. return showToast(context, message, toastLength: Toast.LENGTH_SHORT);
  40. }