Flutter通用UI之EmptyPage

示例图:

在这里插入图片描述

在这里插入图片描述

功能详解

EmptyPage支持自定义图片,文案,按钮是否展示,按钮字体大小,字体色值,边框,背景色

代码

import 'package:flutter/material.dart';

class EmptyPage extends StatelessWidget {
  final String imageUrl; //占位图
  final String desc; //描述
  bool hideBtn; //是否隐藏重新加载按钮
  OnBtnClickListener listener;
  Color borderColor;
  Color textColor;
  double textSize;
  double borderRadius;
  String btnText;
  List<Color> list;

  EmptyPage(
      {@required this.imageUrl,
      this.desc,
      this.hideBtn,
      this.listener,
      this.textSize,
      this.textColor,
      this.borderColor,
      this.borderRadius,
      this.btnText,
      this.list});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(width: 120, height: 120, child: Image.asset(imageUrl)),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                desc ?? "",
                style: TextStyle(fontSize: 13, color: Color(0xffc6cdd3)),
              ),
            ),
            _buildRetryBtn()
          ],
        ),
      ),
    );
  }

  Widget _buildRetryBtn() {
    var _hideBtn = hideBtn ?? false;
    var _list = list ?? [Color(0xffFFE251), Color(0xffFDD108)];
    if (!_hideBtn) {
      return Container(
        height: 40,
        margin: EdgeInsets.fromLTRB(0, 20, 0, 0),
        padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
        decoration: BoxDecoration(
            border: Border.all(color: borderColor ?? Colors.black),
            gradient: LinearGradient(colors: _list),
            borderRadius: BorderRadius.circular(borderRadius ?? 20)),
        child: FlatButton(
          onPressed: () {
            listener.onTap();
          },
          highlightColor: Color(0xffFFE251),
          child: Text(
            btnText ?? "重新加载",
            style: TextStyle(
                fontSize: textSize ?? 16,
                color: textColor ?? Color(0xff343a40)),
          ),
        ),
      );
    } else {
      return Container();
    }
  }
}

abstract class OnBtnClickListener {
  void onTap();
}

代码调用

EmptyPage(imageUrl: "images/nonet.png",desc: "网络飞走了",)

点击事件回调

 @override
  void onTap() {
    // TODO: implement onTap
  }

属性含义

属性含义
imageUrl图片地址
desc文案描述
hideBtn是否隐藏按钮
listener点击回调
borderColor按钮边框颜色
textColor字体颜色
textSize字体大小
borderRadius按钮弧度
btnText按钮文案
list按钮渐变背景色

Demo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值