toast_util.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. Future<void> showToast(String message,
  6. {toastLength = Toast.LENGTH_LONG}) async {
  7. if (Platform.isAndroid) {
  8. await Fluttertoast.cancel();
  9. return Fluttertoast.showToast(
  10. msg: message,
  11. toastLength: toastLength,
  12. gravity: ToastGravity.BOTTOM,
  13. timeInSecForIosWeb: 1,
  14. backgroundColor: Colors.blueGrey[900],
  15. textColor: Colors.white,
  16. fontSize: 16.0);
  17. } else {
  18. EasyLoading.instance
  19. ..backgroundColor = Colors.blueGrey[900]
  20. ..indicatorColor = Colors.blueGrey[900]
  21. ..textColor = Colors.white
  22. ..userInteractions = true
  23. ..loadingStyle = EasyLoadingStyle.custom;
  24. return EasyLoading.showToast(
  25. message,
  26. duration: Duration(seconds: (toastLength == Toast.LENGTH_LONG ? 5 : 2)),
  27. toastPosition: EasyLoadingToastPosition.bottom,
  28. );
  29. }
  30. }
  31. Future<void> showShortToast(String message) {
  32. return showToast(message, toastLength: Toast.LENGTH_SHORT);
  33. }