116 lines
3.7 KiB
Dart
Raw Normal View History

/*
*
* author
* */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart' as ToastPlugins;
class Toast{
/// 土司提示
/// msg: 提示的信息
/// gravity显示的位置
static show({required String msg,ToastPlugins.ToastGravity? gravity}){
ToastPlugins.Fluttertoast.showToast(
msg: msg,
toastLength: ToastPlugins.Toast.LENGTH_SHORT,
gravity: gravity??ToastPlugins.ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
/// 显示模态弹窗
/// context: 上下文
/// title标题
/// content内容
/// confirmText确认按钮文案
/// confirmTextColor确认按钮颜色 默认颜色 const Color(0xFFEE4A42)
/// cancelText取消按钮文案
/// showCancel是否显示取消按钮
/// success: 确认按钮回调函数
/// fail: 取消按钮回调函数
static showModal({
required BuildContext context,
required String title,
required String content,
required String confirmText,
required Function success,
Color? confirmTextColor,
String? cancelText,
bool? showCancel,
Function? fail
}){
confirmTextColor ??= const Color(0xFFE37549);
showCancel ??= true;
cancelText ??= '取消';
showDialog(context: context, builder: (cxt){
return AlertDialog(
buttonPadding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
contentPadding: EdgeInsets.fromLTRB( 55.w, 45.w, 55.w, 70.w),
title: Text(title,textAlign: TextAlign.center,style: TextStyle(
fontSize: 32.sp,
color: const Color(0xff26313B),
fontWeight:FontWeight.w400
)),
content: Text(content,style: TextStyle(
fontSize: 28.sp,
color: const Color(0xff666666),
fontWeight:FontWeight.w400
)),
actions: <Widget>[
Container(
width: double.infinity,
decoration: BoxDecoration(
border: Border(
top: BorderSide(
width: 1.w,//宽度
color: const Color(0xFFEEEEEE), //边框颜色
),
)
),
child: Row(
children: [
showCancel==true?Expanded(child: GestureDetector(
child: Container(
height: 90.w,
alignment: Alignment.center,
child: Text(cancelText!,textAlign: TextAlign.center,style: TextStyle(
fontSize: 28.sp
)),
),
onTap: (){
Navigator.of(cxt).pop();
if(fail!=null){
fail();
}
},
)):const SizedBox(width: 0,height: 0),
showCancel==true?Container(width: 1.w,height: 60.w,color: const Color(0xffEEEEEE)):const SizedBox(width: 0,height: 0),
Expanded(child: GestureDetector(
child: Container(
height: 90.w,
alignment: Alignment.center,
child: Text(confirmText,textAlign: TextAlign.center,style: TextStyle(
fontSize: 28.sp,
color: confirmTextColor
)),
),
onTap: (){
Navigator.of(cxt).pop();
if(success!=null){
success();
}
},
)),
],
),
)
],
);
});
}
}