material_footer.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:eye_video/framework/uikit/refresher/indicator/core/abstract_footer.dart';
  2. import 'package:eye_video/framework/uikit/refresher/indicator/core/footer_link_notifier.dart';
  3. import 'package:eye_video/framework/uikit/refresher/sliver/sliver_loading.dart';
  4. import 'package:flutter/material.dart';
  5. class MaterialFooter extends Footer {
  6. final Key key;
  7. final double displacement;
  8. // 颜色
  9. final Animation<Color> valueColor;
  10. // 背景颜色
  11. final Color backgroundColor;
  12. final LinkFooterNotifier linkNotifier = LinkFooterNotifier();
  13. MaterialFooter({
  14. this.key,
  15. this.displacement = 40.0,
  16. this.valueColor,
  17. this.backgroundColor,
  18. completeDuration = const Duration(seconds: 1),
  19. bool enableHapticFeedback = false,
  20. bool enableInfiniteLoad = true,
  21. }) : super(
  22. float: true,
  23. extent: 52.0,
  24. triggerDistance: 52.0,
  25. completeDuration: completeDuration == null
  26. ? Duration(
  27. milliseconds: 300,
  28. )
  29. : completeDuration +
  30. Duration(
  31. milliseconds: 300,
  32. ),
  33. enableHapticFeedback: enableHapticFeedback,
  34. enableInfiniteLoad: enableInfiniteLoad,
  35. );
  36. @override
  37. Widget contentBuilder(
  38. BuildContext context,
  39. LoadMode loadState,
  40. double pulledExtent,
  41. double loadTriggerPullDistance,
  42. double loadIndicatorExtent,
  43. AxisDirection axisDirection,
  44. bool float,
  45. Duration completeDuration,
  46. bool enableInfiniteLoad,
  47. bool success,
  48. bool noMore) {
  49. linkNotifier.contentBuilder(
  50. context,
  51. loadState,
  52. pulledExtent,
  53. loadTriggerPullDistance,
  54. loadIndicatorExtent,
  55. axisDirection,
  56. float,
  57. completeDuration,
  58. enableInfiniteLoad,
  59. success,
  60. noMore);
  61. return MaterialFooterWidget(
  62. key: key,
  63. displacement: displacement,
  64. valueColor: valueColor,
  65. backgroundColor: backgroundColor,
  66. linkNotifier: linkNotifier,
  67. );
  68. }
  69. }
  70. // 质感设计Footer组件
  71. class MaterialFooterWidget extends StatefulWidget {
  72. final double displacement;
  73. // 颜色
  74. final Animation<Color> valueColor;
  75. // 背景颜色
  76. final Color backgroundColor;
  77. final LinkFooterNotifier linkNotifier;
  78. const MaterialFooterWidget({
  79. Key key,
  80. this.displacement,
  81. this.valueColor,
  82. this.backgroundColor,
  83. this.linkNotifier,
  84. }) : super(key: key);
  85. @override
  86. MaterialFooterWidgetState createState() {
  87. return MaterialFooterWidgetState();
  88. }
  89. }
  90. class MaterialFooterWidgetState extends State<MaterialFooterWidget> {
  91. LoadMode get _refreshState => widget.linkNotifier.loadState;
  92. double get _pulledExtent => widget.linkNotifier.pulledExtent;
  93. double get _riggerPullDistance => widget.linkNotifier.loadTriggerPullDistance;
  94. AxisDirection get _axisDirection => widget.linkNotifier.axisDirection;
  95. bool get _noMore => widget.linkNotifier.noMore;
  96. @override
  97. Widget build(BuildContext context) {
  98. if (_noMore) return Container();
  99. // 是否为垂直方向
  100. bool isVertical = _axisDirection == AxisDirection.down ||
  101. _axisDirection == AxisDirection.up;
  102. // 是否反向
  103. bool isReverse = _axisDirection == AxisDirection.up ||
  104. _axisDirection == AxisDirection.left;
  105. // 计算进度值
  106. double indicatorValue = _pulledExtent / _riggerPullDistance;
  107. indicatorValue = indicatorValue < 1.0 ? indicatorValue : 1.0;
  108. return Stack(
  109. children: [
  110. Positioned(
  111. top: isVertical ? !isReverse ? 0.0 : null : 0.0,
  112. bottom: isVertical ? isReverse ? 0.0 : null : 0.0,
  113. left: !isVertical ? !isReverse ? 0.0 : null : 0.0,
  114. right: !isVertical ? isReverse ? 0.0 : null : 0.0,
  115. child: Container(
  116. alignment: isVertical
  117. ? !isReverse ? Alignment.topCenter : Alignment.bottomCenter
  118. : !isReverse ? Alignment.centerLeft : Alignment.centerRight,
  119. child: RefreshProgressIndicator(
  120. value: _refreshState == LoadMode.armed ||
  121. _refreshState == LoadMode.load ||
  122. _refreshState == LoadMode.loaded ||
  123. _refreshState == LoadMode.done
  124. ? null
  125. : indicatorValue,
  126. valueColor: widget.valueColor,
  127. backgroundColor: widget.backgroundColor,
  128. ),
  129. ),
  130. ),
  131. ],
  132. );
  133. }
  134. }