You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.4 KiB
136 lines
4.4 KiB
3 weeks ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
|
import 'package:get/get.dart';
|
||
3 weeks ago
|
import 'package:intl/intl.dart';
|
||
2 weeks ago
|
import 'package:problem_check_system/data/models/problem_model.dart';
|
||
|
import 'package:problem_check_system/shared/widgets/custom_button.dart';
|
||
|
import 'package:problem_check_system/modules/problem/views/problem_form_page.dart';
|
||
3 weeks ago
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||
|
|
||
3 weeks ago
|
// 定义枚举类型
|
||
|
enum ProblemCardViewType { buttons, checkbox }
|
||
|
|
||
3 weeks ago
|
class ProblemCard extends StatelessWidget {
|
||
3 weeks ago
|
final Problem problem;
|
||
|
final ProblemCardViewType viewType;
|
||
3 weeks ago
|
|
||
3 weeks ago
|
const ProblemCard(
|
||
|
this.problem, {
|
||
3 weeks ago
|
super.key,
|
||
3 weeks ago
|
this.viewType = ProblemCardViewType.buttons,
|
||
|
});
|
||
3 weeks ago
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Card(
|
||
2 weeks ago
|
// margin: EdgeInsets.symmetric(vertical: 5.h, horizontal: 9.w),
|
||
3 weeks ago
|
child: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
ListTile(
|
||
|
leading: Image.asset(
|
||
|
'assets/images/problem_preview.png',
|
||
3 weeks ago
|
fit: BoxFit.contain,
|
||
3 weeks ago
|
),
|
||
3 weeks ago
|
title: Text('问题描述', style: TextStyle(fontSize: 16.sp)),
|
||
3 weeks ago
|
subtitle: LayoutBuilder(
|
||
|
builder: (context, constraints) {
|
||
|
return Text(
|
||
3 weeks ago
|
problem.description,
|
||
3 weeks ago
|
maxLines: 2,
|
||
|
overflow: TextOverflow.ellipsis,
|
||
3 weeks ago
|
style: TextStyle(fontSize: 14.sp),
|
||
3 weeks ago
|
);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
SizedBox(height: 8.h),
|
||
|
Row(
|
||
|
children: [
|
||
|
SizedBox(width: 16.w),
|
||
|
Row(
|
||
|
children: [
|
||
|
Icon(Icons.location_on, color: Colors.grey, size: 16.h),
|
||
|
SizedBox(width: 8.w),
|
||
3 weeks ago
|
Text(problem.location, style: TextStyle(fontSize: 12.sp)),
|
||
3 weeks ago
|
],
|
||
|
),
|
||
|
SizedBox(width: 16.w),
|
||
|
Row(
|
||
|
children: [
|
||
|
Icon(Icons.access_time, color: Colors.grey, size: 16.h),
|
||
|
SizedBox(width: 8.w),
|
||
|
Text(
|
||
3 weeks ago
|
DateFormat('yyyy-MM-dd HH:mm').format(problem.createdAt),
|
||
3 weeks ago
|
style: TextStyle(fontSize: 12.sp),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
SizedBox(height: 8.h),
|
||
|
Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
children: <Widget>[
|
||
|
SizedBox(width: 16.w),
|
||
3 weeks ago
|
Wrap(
|
||
|
spacing: 8,
|
||
3 weeks ago
|
children: [
|
||
3 weeks ago
|
problem.isUploaded
|
||
|
? TDTag('已上传', isLight: true, theme: TDTagTheme.success)
|
||
|
: TDTag('未上传', isLight: true, theme: TDTagTheme.danger),
|
||
|
problem.boundInfo != null && problem.boundInfo!.isNotEmpty
|
||
|
? TDTag('已绑定', isLight: true, theme: TDTagTheme.primary)
|
||
|
: TDTag('未绑定', isLight: true, theme: TDTagTheme.warning),
|
||
3 weeks ago
|
],
|
||
|
),
|
||
3 weeks ago
|
const Spacer(), // 使用 Spacer 替代固定的 SizedBox
|
||
|
_buildBottomActions(),
|
||
3 weeks ago
|
],
|
||
|
),
|
||
3 weeks ago
|
SizedBox(height: 8.h),
|
||
3 weeks ago
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
3 weeks ago
|
// 渲染底部 UI 的私有方法
|
||
|
Widget _buildBottomActions() {
|
||
|
switch (viewType) {
|
||
|
case ProblemCardViewType.buttons:
|
||
|
return Row(
|
||
|
children: [
|
||
|
CustomButton(
|
||
|
text: '修改',
|
||
|
onTap: () {
|
||
2 weeks ago
|
Get.to(ProblemFormPage(problem: problem));
|
||
3 weeks ago
|
},
|
||
|
),
|
||
|
SizedBox(width: 8.w),
|
||
|
CustomButton(
|
||
|
text: '查看',
|
||
|
onTap: () {
|
||
2 weeks ago
|
Get.to(ProblemFormPage(problem: problem, isReadOnly: true));
|
||
3 weeks ago
|
},
|
||
|
),
|
||
|
SizedBox(width: 16.w),
|
||
|
],
|
||
|
);
|
||
|
case ProblemCardViewType.checkbox:
|
||
|
return Padding(
|
||
|
padding: EdgeInsets.only(right: 16.w),
|
||
|
child: Obx(
|
||
|
() => Checkbox(
|
||
|
// 将 Checkbox 的 value 绑定到 controller.isChecked.value
|
||
|
value: problem.isChecked.value,
|
||
|
// 当 Checkbox 状态改变时,调用 controller 中的方法来更新状态
|
||
|
onChanged: (bool? value) {
|
||
|
problem.isChecked.value = value ?? false;
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
3 weeks ago
|
}
|
||
|
}
|