Flutter自定义加载中的Loading

一、定义

class YmDialog extends Dialog {
  final String title;

  const YmDialog(this.title, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      //创建透明层
      child: Material(
        type: MaterialType.transparency, //透明类型
        child: SizedBox(
          width: 120,
          height: 120,
          child: Container(
            decoration: ShapeDecoration(
                color: ThemeColors.color585858,
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(5.0)))),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const CircularProgressIndicator(
                  color: Colors.white,
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 14),
                  child: Text(
                    title,
                    style: const TextStyle(fontSize: 14.0, color: Colors.white),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

二、显示

showDialog(
  context: context,
  barrierColor: Colors.transparent, //背景透明
  barrierDismissible: false, // 屏蔽点击对话框外部自动关闭
  builder: (BuildContext context) {
    return const YmDialog("加载中…");
});

缺点:

无法点击穿透dialog后面的页面事件,例如首页的显示图片,显示加载中后面的「点击显示消息提示框」就无法响应,如果有这个需求的就不能用了,需使用第三方库flutter_smart_dialog:

https://pub.flutter-io.cn/packages/flutter_smart_dialog/install

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值