swipecard.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import 'package:fis_common/helpers/color.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flyinsonolite/infrastructure/scale.dart';
  4. import 'package:flyinsonolite/infrastructure/storage.dart';
  5. class SwipeCard extends StatefulWidget {
  6. final Widget child;
  7. final int? index;
  8. final Function onTap;
  9. final bool isActive;
  10. final EdgeInsets forbiddenAnimationMargin;
  11. final EdgeInsets forbiddenAnimationPadding;
  12. /// 是否禁用动画
  13. final bool? isForbiddenAnimation;
  14. const SwipeCard({
  15. Key? key,
  16. this.index,
  17. required this.child,
  18. required this.onTap,
  19. required this.isActive,
  20. this.forbiddenAnimationMargin = const EdgeInsets.only(
  21. right: 22,
  22. left: 22,
  23. ),
  24. this.forbiddenAnimationPadding = const EdgeInsets.only(
  25. top: 20,
  26. bottom: 10,
  27. left: 15,
  28. right: 0,
  29. ),
  30. this.isForbiddenAnimation = false,
  31. }) : super(key: key);
  32. @override
  33. State<SwipeCard> createState() => _SwipeCardState();
  34. }
  35. class _SwipeCardState extends State<SwipeCard> {
  36. bool hovering = false;
  37. Widget _buildChild() {
  38. EdgeInsets margin = EdgeInsets.only(
  39. right: 22.s,
  40. left: 22.s,
  41. );
  42. Color color = Colors.white;
  43. BoxShadow boxShadow = BoxShadow(
  44. color: FColorHelper.mixColor(
  45. Colors.black12,
  46. Colors.black38,
  47. 70,
  48. ),
  49. offset: Offset(3.s, 3.s), //阴影y轴偏移量
  50. blurRadius: 6.s, //阴影模糊程度
  51. spreadRadius: 0, //阴影扩散程度
  52. );
  53. EdgeInsets padding =
  54. EdgeInsets.only(top: 20.s, bottom: 10.s, left: 15.s, right: 0);
  55. if (hovering && !widget.isActive) {
  56. margin = EdgeInsets.only(
  57. right: 15.s,
  58. left: 15.s,
  59. );
  60. color = Storage.currentTheme.themeData.indicatorColor;
  61. boxShadow = BoxShadow(
  62. color: color,
  63. offset: Offset(3.s, 3.s), //阴影y轴偏移量
  64. blurRadius: 6.s, //阴影模糊程度
  65. spreadRadius: 0, //阴影扩散程度
  66. );
  67. padding = EdgeInsets.only(
  68. top: 20.s,
  69. bottom: 10.s,
  70. left: 22.s,
  71. right: 0,
  72. );
  73. } else if (widget.isActive) {
  74. //color = FTheme.ins.colorScheme.primary;
  75. boxShadow = BoxShadow(
  76. color: FColorHelper.mixColor(
  77. color,
  78. Colors.black,
  79. 70,
  80. ),
  81. offset: Offset(3.s, 3.s), //阴影y轴偏移量
  82. blurRadius: 6.s, //阴影模糊程度
  83. spreadRadius: 0, //阴影扩散程度
  84. );
  85. }
  86. return AnimatedContainer(
  87. duration: const Duration(milliseconds: 200),
  88. decoration: BoxDecoration(
  89. color: color,
  90. borderRadius: BorderRadius.all(
  91. Radius.circular(8.s),
  92. ),
  93. boxShadow: [
  94. boxShadow,
  95. ],
  96. ),
  97. margin: widget.isForbiddenAnimation!
  98. ? widget.forbiddenAnimationMargin
  99. : margin,
  100. padding: widget.isForbiddenAnimation!
  101. ? widget.forbiddenAnimationPadding
  102. : padding,
  103. child: widget.child,
  104. );
  105. }
  106. @override
  107. Widget build(BuildContext context) {
  108. return MouseRegion(
  109. cursor: SystemMouseCursors.click,
  110. onEnter: (e) {
  111. setState(() {
  112. hovering = true;
  113. });
  114. },
  115. onExit: (e) {
  116. setState(() {
  117. hovering = false;
  118. });
  119. },
  120. child: GestureDetector(
  121. onTap: () {
  122. setState(() {
  123. widget.onTap();
  124. });
  125. },
  126. child: Column(
  127. children: [
  128. _buildChild(),
  129. SizedBox(height: 15.s),
  130. ],
  131. ),
  132. ),
  133. );
  134. }
  135. }