| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import '../../../resource/colors.gen.dart';
- import '../../../widget/gradient_text.dart';
- import '../intimacy_analyse_upload/widget/step_label_widget.dart';
- /// 步骤卡片,支持设置卡片背景、步骤标题、步骤描述、顶部图标和内容区域
- class StepCard extends StatelessWidget {
- /// 卡片背景
- final ImageProvider? bgImageProvider;
- /// 步骤标签
- final String? stepLabel;
- /// 步骤标题
- final String? stepTitle;
- /// 步骤描述
- final String? stepDesc;
- /// 顶部图标
- final Image? topIconWidget;
- /// 内容组件
- final Widget contentWidget;
- /// 是否有步骤
- final bool hasStep;
- const StepCard({
- super.key,
- this.bgImageProvider,
- this.stepLabel,
- this.stepTitle,
- this.stepDesc,
- this.hasStep = true,
- required this.contentWidget,
- this.topIconWidget,
- });
- @override
- Widget build(BuildContext context) {
- BoxDecoration decoration;
- // 没有背景图,使用渐变背景
- if (bgImageProvider == null) {
- decoration = BoxDecoration(
- gradient: LinearGradient(
- colors: [Color(0xFFEFE9FF), Color(0xFFFBFAFF)],
- begin: Alignment.topCenter,
- end: Alignment.bottomRight,
- ),
- shape: BoxShape.rectangle,
- border: Border.all(color: ColorName.white80, width: 1.w),
- borderRadius: BorderRadius.all(Radius.circular(20.r)),
- );
- } else {
- // 背景图
- decoration = BoxDecoration(
- image: DecorationImage(image: bgImageProvider!, fit: BoxFit.fill),
- );
- }
- return Container(
- margin: EdgeInsets.only(left: 12.w, top: 10.h, right: 12.w),
- child: Stack(
- // 不裁切超出区域的子组件,例如下面的顶部的图标
- clipBehavior: Clip.none,
- children: [
- // 顶部的图标
- topIconWidget == null
- ? SizedBox()
- : Positioned(top: -11.h, right: 0, child: topIconWidget!),
- // 卡片背景
- Container(
- decoration: decoration,
- child: Column(
- // 左对齐
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildStepLayout(),
- // 内容区域
- contentWidget,
- SizedBox(height: 12.h),
- ],
- ),
- ),
- ],
- ),
- );
- }
- /// 步骤
- Widget _buildStepLayout() {
- if (!hasStep) {
- return SizedBox();
- }
- String stepDescStr = stepDesc ?? "";
- return Column(
- children: [
- // 步骤标题
- Container(
- margin: EdgeInsets.only(
- // 存在步骤标签时,才有左边距
- left: _hasStepLabel() ? 12.w : 0,
- top: 16.h,
- bottom: 4.h,
- ),
- child: _buildStepTitle(),
- ),
- SizedBox(height: 4.h),
- // 步骤描述
- stepDescStr.isNotEmpty
- ? _buildStepDesc(stepDescStr)
- : SizedBox(height: 6.h),
- SizedBox(height: 14.h),
- ],
- );
- }
- /// 是否有步骤标签
- bool _hasStepLabel() {
- String stepLabelStr = stepLabel ?? "";
- return stepLabelStr.isNotEmpty == true;
- }
- /// 是否有步骤标题
- bool _hasStepTitle() {
- String stepTitleStr = stepTitle ?? "";
- return stepTitleStr.isNotEmpty == true;
- }
- /// 是否有步骤标题
- bool _hasStepDesc() {
- String stepDescStr = stepDesc ?? "";
- return stepDescStr.isNotEmpty == true;
- }
- /// 步骤标题
- Widget _buildStepTitle() {
- String stepTitleStr = stepTitle ?? "";
- // 步骤标签
- Widget stepLabelWidget;
- if (_hasStepLabel()) {
- stepLabelWidget = StepLabelWidget(label: stepLabel ?? "");
- } else {
- stepLabelWidget = SizedBox();
- }
- return Row(
- children: [
- // 步骤标签
- stepLabelWidget,
- SizedBox(width: 10.w),
- // 标题
- GradientText(
- // 渐变颜色
- colors: [ColorName.stepTitleColor1, ColorName.stepTitleColor2],
- child: Text(
- stepTitleStr,
- style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w700),
- ),
- ),
- ],
- );
- }
- /// 构建步骤描述
- Widget _buildStepDesc(String desc) {
- if (desc.isEmpty) {
- return SizedBox();
- }
- return Row(
- children: [
- Expanded(
- child: Container(
- margin: EdgeInsets.only(left: 12.w, right: 12.w),
- child: Text(
- desc,
- // 超过时显示省略号
- overflow: TextOverflow.ellipsis,
- // 最多多少行
- maxLines: 2,
- style: TextStyle(
- fontSize: 12.sp,
- fontWeight: FontWeight.w400,
- color: ColorName.black60,
- ),
- ),
- ),
- ),
- SizedBox(height: 16.h),
- ],
- );
- }
- }
|