immich_toast.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:fluttertoast/fluttertoast.dart';
  3. enum ToastType { info, success, error }
  4. class ImmichToast {
  5. static show({
  6. required BuildContext context,
  7. required String msg,
  8. ToastType toastType = ToastType.info,
  9. }) {
  10. FToast fToast;
  11. fToast = FToast();
  12. fToast.init(context);
  13. fToast.showToast(
  14. child: Container(
  15. padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
  16. decoration: BoxDecoration(
  17. borderRadius: BorderRadius.circular(5.0),
  18. color: Colors.grey[50],
  19. border: Border.all(
  20. color: Colors.black12,
  21. width: 1,
  22. ),
  23. ),
  24. child: Row(
  25. mainAxisSize: MainAxisSize.min,
  26. children: [
  27. (toastType == ToastType.info)
  28. ? Icon(
  29. Icons.info_outline_rounded,
  30. color: Theme.of(context).primaryColor,
  31. )
  32. : Container(),
  33. (toastType == ToastType.success)
  34. ? const Icon(
  35. Icons.check,
  36. color: Color.fromARGB(255, 104, 248, 140),
  37. )
  38. : Container(),
  39. (toastType == ToastType.error)
  40. ? const Icon(
  41. Icons.error_outline_rounded,
  42. color: Color.fromARGB(255, 240, 162, 156),
  43. )
  44. : Container(),
  45. const SizedBox(
  46. width: 12.0,
  47. ),
  48. Flexible(
  49. child: Text(
  50. msg,
  51. style: TextStyle(
  52. color: Theme.of(context).primaryColor,
  53. fontWeight: FontWeight.bold,
  54. fontSize: 15,
  55. ),
  56. ),
  57. ),
  58. ],
  59. ),
  60. ),
  61. gravity: ToastGravity.TOP,
  62. toastDuration: const Duration(seconds: 2),
  63. );
  64. }
  65. }