step_card.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import '../../../resource/colors.gen.dart';
  5. import '../../../widget/gradient_text.dart';
  6. import '../intimacy_analyse_upload/widget/step_label_widget.dart';
  7. /// 步骤卡片,支持设置卡片背景、步骤标题、步骤描述、顶部图标和内容区域
  8. class StepCard extends StatelessWidget {
  9. /// 卡片背景
  10. final ImageProvider bgImageProvider;
  11. /// 步骤标签
  12. final String? stepLabel;
  13. /// 步骤标题
  14. final String stepTitle;
  15. /// 步骤描述
  16. final String stepDesc;
  17. /// 顶部图标
  18. final Image? topIconWidget;
  19. /// 内容组件
  20. final Widget contentWidget;
  21. const StepCard({
  22. super.key,
  23. required this.bgImageProvider,
  24. required this.stepLabel,
  25. required this.stepTitle,
  26. required this.stepDesc,
  27. required this.contentWidget,
  28. this.topIconWidget,
  29. });
  30. @override
  31. Widget build(BuildContext context) {
  32. return Container(
  33. margin: EdgeInsets.only(left: 12.w, top: 10.h, right: 12.w),
  34. child: Stack(
  35. // 不裁切超出区域的子组件,例如下面的顶部的图标
  36. clipBehavior: Clip.none,
  37. children: [
  38. // 顶部的图标
  39. topIconWidget == null
  40. ? SizedBox()
  41. : Positioned(top: -11.h, right: 0, child: topIconWidget!),
  42. // 卡片背景
  43. Container(
  44. decoration: BoxDecoration(
  45. image: DecorationImage(image: bgImageProvider, fit: BoxFit.fill),
  46. ),
  47. child: Column(
  48. // 左对齐
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. children: [
  51. // 步骤标题
  52. Container(
  53. margin: EdgeInsets.only(left: 12.w, top: 16.h),
  54. child: _buildStepTitle(),
  55. ),
  56. SizedBox(height: 4.h),
  57. // 步骤描述
  58. _buildStepDesc(stepDesc),
  59. SizedBox(height: 16.h),
  60. contentWidget,
  61. SizedBox(height: 18.h),
  62. ],
  63. ),
  64. ),
  65. ],
  66. ),
  67. );
  68. }
  69. /// 步骤标题
  70. Widget _buildStepTitle() {
  71. // 步骤标签
  72. String stepLabelStr = stepLabel ?? "";
  73. Widget stepLabelWidget;
  74. if (stepLabelStr.isBlank == true) {
  75. stepLabelWidget = SizedBox();
  76. } else {
  77. stepLabelWidget = StepLabelWidget(label: stepLabelStr);
  78. }
  79. return Row(
  80. children: [
  81. // 步骤标签
  82. stepLabelWidget,
  83. SizedBox(width: 10.w),
  84. // 标题
  85. GradientText(
  86. // 渐变颜色
  87. colors: [ColorName.stepTitleColor1, ColorName.stepTitleColor2],
  88. child: Text(
  89. stepTitle,
  90. style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w700),
  91. ),
  92. ),
  93. ],
  94. );
  95. }
  96. /// 构建步骤描述
  97. Widget _buildStepDesc(String desc) {
  98. return Container(
  99. margin: EdgeInsets.only(left: 12.w),
  100. child: Text(
  101. desc,
  102. style: TextStyle(
  103. fontSize: 12.sp,
  104. fontWeight: FontWeight.w400,
  105. color: ColorName.black60,
  106. ),
  107. ),
  108. );
  109. }
  110. }