toast_util.dart 742 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class ToastUtil {
  static void showToast(String? txt,
      {ToastDuration toastDuration = ToastDuration.short}) {
    Fluttertoast.showToast(
        msg: txt ?? "",
        toastLength: toastDuration == ToastDuration.long
            ? Toast.LENGTH_LONG
            : Toast.LENGTH_SHORT,
        gravity: ToastGravity.BOTTOM,
        backgroundColor: const Color(0xB3000000),
        textColor: Colors.white,
        fontSize: 17.0);
  }

  static void showLongToast(String? txt) {
    showToast(txt, toastDuration: ToastDuration.long);
  }
}

enum ToastDuration {
  /// Show Short toast for 1 sec
  short,

  /// Show Long toast for 5 sec
  long
}