效果:
fluttertoast: 8.0.9
Fluttertoast.showToast(
msg: "我是弹窗",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.blue,
textColor: Colors.white,
fontSize: 16.0);
创建一个文件FlutterToast.dart: 提供操作成功和失败的两个方法:
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void okToast(String text) {
Fluttertoast.showToast(
msg: text,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.blue,
textColor: Colors.white,
fontSize: 16.0);
}
void errorToast(String text) {
Fluttertoast.showToast(
msg:text,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
最后在需要使用弹窗的地方使用就可以了:
okToast("操作成功的弹窗提示信息!"); //减少了大量的基础代码以及维护成本
errorToast("操作失败的弹窗提示信息!");
因篇幅问题不能全部显示,请点此查看更多更全内容