state_layout.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:liftmanager/res/resources.dart';
  4. import 'package:liftmanager/utils/image_utils.dart';
  5. /// design/9暂无状态页面/index.html#artboard3
  6. class StateLayout extends StatefulWidget {
  7. const StateLayout({
  8. Key key,
  9. @required this.type,
  10. this.hintText
  11. }):super(key: key);
  12. final StateType type;
  13. final String hintText;
  14. @override
  15. _StateLayoutState createState() => _StateLayoutState();
  16. }
  17. class _StateLayoutState extends State<StateLayout> {
  18. String _img;
  19. String _hintText;
  20. @override
  21. Widget build(BuildContext context) {
  22. switch (widget.type){
  23. case StateType.network:
  24. _img = "zwwl";
  25. _hintText = "无网络连接";
  26. break;
  27. case StateType.loading:
  28. _img = "";
  29. _hintText = "加载中...";
  30. break;
  31. case StateType.empty:
  32. _img = "zwxx";
  33. _hintText = "无数据";
  34. break;
  35. }
  36. return Container(
  37. width: double.infinity,
  38. child: Column(
  39. crossAxisAlignment: CrossAxisAlignment.center,
  40. mainAxisAlignment: MainAxisAlignment.center,
  41. children: <Widget>[
  42. widget.type == StateType.loading ? const CupertinoActivityIndicator(radius: 16.0) :
  43. (widget.type == StateType.empty ? Gaps.empty :
  44. Opacity(
  45. opacity: 1,
  46. child: Container(
  47. height: 120.0,
  48. width: 120.0,
  49. decoration: BoxDecoration(
  50. image: DecorationImage(
  51. image: ImageUtils.getAssetImage("state/$_img"),
  52. ),
  53. ),
  54. ))
  55. ),
  56. Gaps.vGap16,
  57. Text(
  58. widget.hintText ?? _hintText,
  59. style: Theme.of(context).textTheme.subtitle.copyWith(fontSize: Dimens.font_sp14),
  60. ),
  61. Gaps.vGap50,
  62. ],
  63. ),
  64. );
  65. }
  66. }
  67. enum StateType {
  68. /// 无网络
  69. network,
  70. /// 加载中
  71. loading,
  72. /// 空
  73. empty
  74. }