Flutter:EasyLoading(loading加载、消息提示)

前言

官方虽然提供了内置的加载指示器和提示信息,但是功能比较简陋,这里推荐:flutter_easyloading

CircularProgressIndicator

CircularProgressIndicator()

在这里插入图片描述
加粗样式

ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
     // 提示的内容
     content: Text("这是一条提示"),
     //   阴影
     elevation: 8,
     //持续时间,默认4秒
     duration: Duration(seconds: 4),
     //颜色
     backgroundColor: Colors.orange,
     //  形状
     shape: RoundedRectangleBorder(
       borderRadius: BorderRadius.all(Radius.circular(20.0)),
     ),
   ));

在这里插入图片描述

基本使用

官方地址
https://pub-web.flutter-io.cn/packages/flutter_easyloading

安装

flutter pub add flutter_easyloading

官方在线示例

https://nslogx.github.io/flutter_easyloading/#/

loading

初始化
首先需要在MaterialApp/CupertinoApp中进行初始化

MaterialApp(
   //指定显示哪一个页面
   home: const YcHomePage(),
   builder: EasyLoading.init(),
 );

简单使用

// 显示指示器
 EasyLoading.show(
   status: '加载中', // 要显示的文字
 );
 //  延时2秒
 Future.delayed(const Duration(seconds: 2), () {
   //  关闭指示器
   EasyLoading.dismiss();
 });

在这里插入图片描述
加载样式的设置
加载样式分为全局设置,和非全局设置。下面以加载wave为例

  • 全局设置
main() {
  runApp(const MyApp());
  configLoading();
}

// 设置loading,其他配置见官方文档
void configLoading() {
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)  // 加载时间
    ..indicatorType = EasyLoadingIndicatorType.wave  // 加载类型
    ..loadingStyle = EasyLoadingStyle.light  // 加载样式
    ..indicatorSize = 45.0   // 大小
    ..maskType = EasyLoadingMaskType.black // 遮罩
    ..userInteractions = true  // 使用单例模式
    ..dismissOnTap = false;  // 指示器结束的点击时间
}

在这里插入图片描述

  • 单独使用
onPressed: () {
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)  // 加载时间
      ..indicatorType = EasyLoadingIndicatorType.cubeGrid  // 加载类型
      ..loadingStyle = EasyLoadingStyle.light  // 加载样式
      ..indicatorSize = 45.0   // 大小
      ..maskType = EasyLoadingMaskType.black // 遮罩
      ..userInteractions = true  // 使用单例模式
      ..dismissOnTap = false;  // 指示器结束的点击时间
    // 显示指示器
    EasyLoading.show(
      status: '加载中', // 要显示的文字
    );
    //  延时2秒
    Future.delayed(const Duration(seconds: 2), () {
      //  关闭指示器
      EasyLoading.dismiss();
    });
  },
  child: const Text("加载"))

消息提示

初始化
首先需要在MaterialApp/CupertinoApp中进行初始化

MaterialApp(
   //指定显示哪一个页面
   home: const YcHomePage(),
   builder: EasyLoading.init(),
 );

showToast

EasyLoading.showToast("这是一个Toast");
//  延时2秒
Future.delayed(const Duration(seconds: 2), () {
  EasyLoading.dismiss();
});

在这里插入图片描述
showInfo

EasyLoading.showInfo("这是一个Info");

在这里插入图片描述
showError

 EasyLoading.showError("这是一个Error");

在这里插入图片描述

showSuccess

 EasyLoading.showSuccess("这是一个success");

在这里插入图片描述
showProgress

EasyLoading.showProgress(0.2,status: '下载中...');

这个不知道是什么情况,没有显示出圆形进度条。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无知的小菜鸡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值