jjsos_autosos_flutter/lib/util/toast.dart

47 lines
1.2 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';
/// Toast 工具类(封装 fluttertoast + EasyLoading
class Toast {
Toast._();
/// 短提示(屏幕底部)
static void show(String message) {
if (message.isEmpty) return;
Fluttertoast.showToast(
msg: message,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: const Color(0xCC000000),
textColor: Colors.white,
fontSize: 14,
);
}
/// 成功样式(顶部绿色弹条)
static void success(String message) {
if (message.isEmpty) return;
EasyLoading.showSuccess(message, duration: const Duration(seconds: 2));
}
/// 失败样式
static void error(String message) {
if (message.isEmpty) return;
EasyLoading.showError(message, duration: const Duration(seconds: 2));
}
/// 警告
static void warn(String message) {
if (message.isEmpty) return;
EasyLoading.showInfo(message, duration: const Duration(seconds: 2));
}
/// Loading
static void loading(String message) {
EasyLoading.show(status: message);
}
static void dismiss() => EasyLoading.dismiss();
}