toast_util.dart 1.5 KB

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