Flutter之Toast的使用

1.在pubspec.yaml中加入依赖

fluttertoast: ^3.0.3

2.更新依赖

3.导入依赖

import 'package:fluttertoast/fluttertoast.dart';

4.在common.dart中实现显示Toast的函数,然后调用即可。

showErrorToast(String msg){
  Fluttertoast.showToast(
    msg:msg,
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIos: 1,
    backgroundColor: Colors.red,
    textColor: Colors.white,
    fontSize: 16.0
  );
}

showCorrectToast(String msg){
  Fluttertoast.showToast(
    msg:msg,
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIos: 1,
    backgroundColor: Colors.green,
    textColor: Colors.white,
    fontSize: 16.0
  );
}

 

posted @ 2021-06-16 21:35  罗毅豪  阅读(1206)  评论(0编辑  收藏  举报