page_exception.dart 2.15 KB
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/widgets/page_empty.dart';
import 'package:one_key/widgets/page_error.dart';
import 'package:one_key/widgets/page_loading.dart';

class ExceptionPage extends StatefulWidget {
  final PageState pageState;
  final VoidCallback callback;

  final String emptyMsg;
  final String emptyImg;
  final String showMsg;
  final Color defalutColor;

  const ExceptionPage(
      {Key key,
      this.pageState = PageState.Loading,
      this.callback,
      this.emptyMsg = "数据为空",
      this.emptyImg = 'bg_error',
      this.showMsg = '',
      this.defalutColor = MyColours.color_ffffff})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ExceptionPageState();
  }
}

class ExceptionPageState extends State<ExceptionPage> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    Widget page = ErrorPage(
      content: "哎呀~网络好像走失了呢",
      callback: widget.callback,
    );
    switch (widget.pageState) {
      case PageState.Loading:
        page = LoadingPage(
            defalutColor: widget.defalutColor, showMsg: widget.showMsg);
        break;
      case PageState.ConnectivityTimeOut:
        page = ErrorPage(
          content: "请求超时啦~刷新一下看看",
          callback: widget.callback,
        );
        break;
      case PageState.ConnectivityError:
        page = ErrorPage(
          content: "哎呀~网络好像走失了呢",
          callback: widget.callback,
        );
        break;
      case PageState.Empty:
        page = EmptyPage(
          content: widget.emptyMsg,
          imgname: widget.emptyImg,
        );
        break;
      case PageState.First:
        page = Container(
          width: 0,
          height: 10,
          color: Colors.white,
        );
        break;
      default:
        page = ErrorPage(
          content: "哎呀~网络好像走失了呢",
          callback: widget.callback,
        );
        break;
    }
    return page;
  }
}