|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:problem_check_system/app/routes/app_routes.dart';
|
|
|
|
import 'package:problem_check_system/data/models/sync_status.dart';
|
|
|
|
import 'package:problem_check_system/data/models/problem_model.dart';
|
|
|
|
import 'package:problem_check_system/modules/problem/views/widgets/custom_button.dart';
|
|
|
|
import 'package:problem_check_system/modules/problem/views/problem_form_page.dart';
|
|
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
|
|
|
|
|
// 定义枚举类型
|
|
|
|
enum ProblemCardViewType { buttons, checkbox }
|
|
|
|
|
|
|
|
class ProblemCard extends StatelessWidget {
|
|
|
|
final Problem problem;
|
|
|
|
final ProblemCardViewType viewType;
|
|
|
|
final Function(Problem, bool)? onChanged;
|
|
|
|
final bool isSelected; // 改为必需参数
|
|
|
|
|
|
|
|
const ProblemCard({
|
|
|
|
super.key,
|
|
|
|
required this.problem,
|
|
|
|
this.viewType = ProblemCardViewType.buttons,
|
|
|
|
this.onChanged,
|
|
|
|
required this.isSelected, // 改为必需参数
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: viewType == ProblemCardViewType.checkbox
|
|
|
|
? () {
|
|
|
|
// 点击卡片时切换选中状态
|
|
|
|
onChanged?.call(problem, !isSelected);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
leading: Image.asset(
|
|
|
|
'assets/images/problem_preview.png',
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
),
|
|
|
|
title: Text('问题描述', style: TextStyle(fontSize: 16.sp)),
|
|
|
|
subtitle: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
return Text(
|
|
|
|
problem.description,
|
|
|
|
maxLines: 2,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(fontSize: 14.sp),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 8.h),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
SizedBox(width: 16.w),
|
|
|
|
Icon(Icons.location_on, color: Colors.grey, size: 16.h),
|
|
|
|
SizedBox(width: 8.w),
|
|
|
|
SizedBox(
|
|
|
|
width: 100.w,
|
|
|
|
child: Text(
|
|
|
|
problem.location,
|
|
|
|
style: TextStyle(fontSize: 12.sp),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 16.w),
|
|
|
|
Icon(Icons.access_time, color: Colors.grey, size: 16.h),
|
|
|
|
SizedBox(width: 8.w),
|
|
|
|
SizedBox(
|
|
|
|
width: 100.w,
|
|
|
|
child: Text(
|
|
|
|
DateFormat('yyyy-MM-dd HH:mm').format(problem.creationTime),
|
|
|
|
style: TextStyle(fontSize: 12.sp),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 8.h),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(width: 16.w),
|
|
|
|
Wrap(
|
|
|
|
spacing: 8,
|
|
|
|
children: [
|
|
|
|
problem.syncStatus == SyncStatus.synced
|
|
|
|
? TDTag('已上传', isLight: true, theme: TDTagTheme.success)
|
|
|
|
: TDTag('未上传', isLight: true, theme: TDTagTheme.danger),
|
|
|
|
problem.bindData != null && problem.bindData!.isNotEmpty
|
|
|
|
? TDTag('已绑定', isLight: true, theme: TDTagTheme.primary)
|
|
|
|
: TDTag(
|
|
|
|
'未绑定',
|
|
|
|
isLight: true,
|
|
|
|
theme: TDTagTheme.warning,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
_buildBottomActions(), // 移除参数
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 8.h),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildBottomActions() {
|
|
|
|
switch (viewType) {
|
|
|
|
case ProblemCardViewType.buttons:
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
CustomButton(
|
|
|
|
text: '修改',
|
|
|
|
onTap: () {
|
|
|
|
Get.toNamed(AppRoutes.problemForm, arguments: problem);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SizedBox(width: 8.w),
|
|
|
|
CustomButton(
|
|
|
|
text: '查看',
|
|
|
|
onTap: () {
|
|
|
|
Get.toNamed(
|
|
|
|
AppRoutes.problemForm,
|
|
|
|
arguments: problem,
|
|
|
|
parameters: {'isReadOnly': 'true'},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SizedBox(width: 16.w),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
case ProblemCardViewType.checkbox:
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(right: 16.w),
|
|
|
|
child: Checkbox(
|
|
|
|
value: isSelected, // 使用组件的选中状态
|
|
|
|
onChanged: (bool? value) {
|
|
|
|
if (value != null) {
|
|
|
|
onChanged?.call(problem, value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|