flutter弹窗:fluttertoast
在开发过程中需要向用户反馈消息的场景有很多,如检验接口调用的结果,表单验证的提示消息等,为此我们基于三方库fluttertoast进行简单的封装,方便开发中调用:
在终端执行
$ flutter pub add fluttertoast
检查 pubspec.yaml 文件中是否已添加 fluttertoast 依赖:
dependencies:flutter:sdk: flutterfluttertoast: ^8.2.12
但是官方的fluttertoast(https://pub.dev/packages/fluttertoast)不支持鸿蒙,所以用第三方插件(https://gitee.com/Megasu/flutter_enjoy_plus_v1.3/)
1、D盘需新建flutter_cache文件夹,高级系统设置添加环境变量,
2、在pubspec.yaml文件注释掉刚才下载的官方包,重新配置
# fluttertoast: ^8.2.12fluttertoast: git:url: https://gitcode.com/openharmony-sig/flutter_fluttertoast.gitref: br_8.2.8_ohos
安装完成后就可以用了
TextButton(onPressed: () {Fluttertoast.showToast(msg: '测试弹窗',toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.BOTTOM, // 位置(移动端)backgroundColor: const Color(0xff42729d), // 背景色(移动端)textColor: Colors.white, // 文字颜色webPosition: 'center', // 位置(web端)webBgColor: '#42729d', // 背景色(web端));},child: Text('弹窗')),