ar_tourism_flutter_unity/lib/components/toastUtil.dart
2025-05-14 17:04:13 +08:00

38 lines
940 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,
);
}
}