38 lines
940 B
Dart
38 lines
940 B
Dart
import 'package:flutter/material.dart';
|
||
import 'package:fluttertoast/fluttertoast.dart';
|
||
|
||
class ToastUtil {
|
||
// 成功提示
|
||
static void showSuccessToast(String message) {
|
||
_showToast(message, Colors.green);
|
||
}
|
||
|
||
// 错误提示
|
||
static void showErrorToast(String message) {
|
||
_showToast(message, Colors.red);
|
||
}
|
||
|
||
// 普通提示
|
||
static void showInfoToast(String message) {
|
||
_showToast(message, Colors.blue);
|
||
}
|
||
|
||
// 自定义颜色提示
|
||
static void showCustomToast(String message, Color backgroundColor) {
|
||
_showToast(message, backgroundColor);
|
||
}
|
||
|
||
// 内部方法,用于展示Toast
|
||
static void _showToast(String message, Color backgroundColor) {
|
||
Fluttertoast.showToast(
|
||
msg: message,
|
||
toastLength: Toast.LENGTH_SHORT,
|
||
gravity: ToastGravity.CENTER,
|
||
timeInSecForIosWeb: 1,
|
||
backgroundColor: backgroundColor,
|
||
textColor: Colors.white,
|
||
fontSize: 16.0,
|
||
);
|
||
}
|
||
}
|