83 lines
2.4 KiB
Dart
83 lines
2.4 KiB
Dart
/*
|
|
* @Author: wangyang 1147192855@qq.com
|
|
* @Date: 2022-07-13 16:31:05
|
|
* @LastEditors: wangyang 1147192855@qq.com
|
|
* @LastEditTime: 2022-07-28 11:56:13
|
|
* @FilePath: \marking_app\lib\utils\toast_utils.dart
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
class ToastUtils {
|
|
static void getFluttertoast({
|
|
required BuildContext context,
|
|
required String msg,
|
|
Toast? toastLength,
|
|
int timeInSecForIosWeb = 1,
|
|
double? fontSize,
|
|
ToastGravity? gravity,
|
|
Color? backgroundColor,
|
|
Color? textColor,
|
|
}) {
|
|
Fluttertoast.showToast(
|
|
msg: msg,
|
|
toastLength: toastLength ?? Toast.LENGTH_SHORT,
|
|
gravity: gravity ?? ToastGravity.CENTER,
|
|
timeInSecForIosWeb: timeInSecForIosWeb,
|
|
backgroundColor: backgroundColor ?? Theme.of(context).primaryColor,
|
|
textColor: textColor ?? Colors.white,
|
|
fontSize: fontSize ?? 16.sp,
|
|
);
|
|
}
|
|
|
|
static void getErrFluttertoast({
|
|
required BuildContext context,
|
|
required String msg,
|
|
ToastGravity gravity = ToastGravity.BOTTOM,
|
|
Color backgroundColor = Colors.grey,
|
|
Toast? toastLength,
|
|
int timeInSecForIosWeb = 1,
|
|
double? fontSize,
|
|
Color? textColor,
|
|
}) {
|
|
ToastUtils.getFluttertoast(
|
|
context: context,
|
|
msg: msg,
|
|
toastLength: toastLength ?? Toast.LENGTH_SHORT,
|
|
gravity: gravity,
|
|
timeInSecForIosWeb: timeInSecForIosWeb,
|
|
backgroundColor: backgroundColor,
|
|
textColor: textColor ?? Colors.white,
|
|
fontSize: fontSize ?? 16.sp,
|
|
);
|
|
}
|
|
|
|
static showError(String showMsg) {
|
|
EasyLoading.showError(showMsg);
|
|
}
|
|
|
|
static showLoading() {
|
|
EasyLoading.show(status: 'loading...');
|
|
}
|
|
|
|
static showInfo(String showMsg, {Duration? duration}) {
|
|
EasyLoading.showInfo(showMsg, duration: duration);
|
|
}
|
|
|
|
static showInfoSimple(String showMsg, int microseconds) {
|
|
EasyLoading.showInfo(showMsg, duration: Duration(microseconds: microseconds));
|
|
}
|
|
|
|
static showSuccess(String showMsg, {Duration? duration}) {
|
|
EasyLoading.showSuccess(showMsg, duration: duration);
|
|
}
|
|
|
|
static dismiss() {
|
|
EasyLoading.dismiss();
|
|
}
|
|
}
|