Browse Source

feat : 图片删除效果

dev
徐振升 1 day ago
parent
commit
b614000b77
  1. 7
      lib/data/providers/sqlite_provider.dart
  2. 11
      lib/modules/problem/controllers/problem_controller.dart
  3. 1
      lib/modules/problem/views/problem_page.dart
  4. 8
      lib/modules/problem/views/problem_upload_page.dart
  5. 162
      lib/modules/problem/views/widgets/problem_card.dart

7
lib/data/providers/sqlite_provider.dart

@ -136,14 +136,9 @@ class SQLiteProvider extends GetxService {
/// ///
Future<int> updateProblem(Problem problem) async { Future<int> updateProblem(Problem problem) async {
try { try {
//
final problemToUpdate = problem.copyWith(
syncStatus: SyncStatus.notSynced,
);
final result = await _database.update( final result = await _database.update(
_tableName, _tableName,
problemToUpdate.toMap(), problem.toMap(),
where: 'id = ?', where: 'id = ?',
whereArgs: [problem.id], whereArgs: [problem.id],
); );

11
lib/modules/problem/controllers/problem_controller.dart

@ -331,7 +331,15 @@ class ProblemController extends GetxController
if (picked != null) { if (picked != null) {
// //
historyStartTime.value = picked.start; historyStartTime.value = picked.start;
historyEndTime.value = picked.end; historyEndTime.value = DateTime(
picked.end.year,
picked.end.month,
picked.end.day,
23,
59,
59,
999,
);
loadProblems(); loadProblems();
log('选择的日期范围是: ${picked.start}${picked.end}'); log('选择的日期范围是: ${picked.start}${picked.end}');
} }
@ -394,6 +402,7 @@ class ProblemController extends GetxController
/// ///
void showUploadPage() { void showUploadPage() {
Get.toNamed(AppRoutes.problemUpload); Get.toNamed(AppRoutes.problemUpload);
clearSelection();
loadUnUploadedProblems(); loadUnUploadedProblems();
} }

1
lib/modules/problem/views/problem_page.dart

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:problem_check_system/app/routes/app_routes.dart';
import 'package:problem_check_system/modules/problem/controllers/problem_controller.dart'; import 'package:problem_check_system/modules/problem/controllers/problem_controller.dart';
import 'package:problem_check_system/modules/problem/views/problem_list_page.dart'; // ProblemListPage import 'package:problem_check_system/modules/problem/views/problem_list_page.dart'; // ProblemListPage
import 'package:problem_check_system/modules/problem/views/widgets/current_filter_bar.dart'; import 'package:problem_check_system/modules/problem/views/widgets/current_filter_bar.dart';

8
lib/modules/problem/views/problem_upload_page.dart

@ -24,7 +24,13 @@ class ProblemUploadPage extends GetView<ProblemController> {
return Text('已选择$selectedCount项'); return Text('已选择$selectedCount项');
}), }),
centerTitle: true, centerTitle: true,
leading: IconButton(icon: Icon(Icons.close), onPressed: () => Get.back()), // leading: IconButton(
// icon: Icon(Icons.close),
// onPressed: () {
// Get.back();
// controller.clearSelection();
// },
// ),
actions: [ actions: [
Obx( Obx(
() => TextButton( () => TextButton(

162
lib/modules/problem/views/widgets/problem_card.dart

@ -6,8 +6,8 @@ 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/sync_status.dart';
import 'package:problem_check_system/data/models/problem_model.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/widgets/custom_button.dart';
import 'package:problem_check_system/modules/problem/views/problem_form_page.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'dart:io'; //
// //
enum ProblemCardViewType { buttons, checkbox } enum ProblemCardViewType { buttons, checkbox }
@ -28,11 +28,20 @@ class ProblemCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
//
final bool isDeleted = problem.isDeleted;
final Color cardColor = isDeleted
? Colors.grey[300]!
: Theme.of(context).cardColor;
final Color contentColor = isDeleted
? Colors.grey[600]!
: Theme.of(context).textTheme.bodyMedium!.color!;
return Card( return Card(
color: cardColor,
child: InkWell( child: InkWell(
onTap: viewType == ProblemCardViewType.checkbox onTap: viewType == ProblemCardViewType.checkbox
? () { ? () {
//
onChanged?.call(problem, !isSelected); onChanged?.call(problem, !isSelected);
} }
: null, : null,
@ -40,18 +49,18 @@ class ProblemCard extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
leading: Image.asset( leading: _buildImageWidget(isDeleted), // 使
'assets/images/problem_preview.png', title: Text(
fit: BoxFit.contain, '问题描述',
style: TextStyle(fontSize: 16.sp, color: contentColor),
), ),
title: Text('问题描述', style: TextStyle(fontSize: 16.sp)),
subtitle: LayoutBuilder( subtitle: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
return Text( return Text(
problem.description, problem.description,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14.sp), style: TextStyle(fontSize: 14.sp, color: contentColor),
); );
}, },
), ),
@ -60,27 +69,26 @@ class ProblemCard extends StatelessWidget {
Row( Row(
children: [ children: [
SizedBox(width: 16.w), SizedBox(width: 16.w),
Icon(Icons.location_on, color: Colors.grey, size: 16.h), Icon(Icons.location_on, color: contentColor, size: 16.h),
SizedBox(width: 8.w), SizedBox(width: 8.w),
SizedBox( SizedBox(
width: 100.w, width: 100.w,
child: Text( child: Text(
problem.location, problem.location,
style: TextStyle(fontSize: 12.sp), style: TextStyle(fontSize: 12.sp, color: contentColor),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
), ),
), ),
SizedBox(width: 16.w), SizedBox(width: 16.w),
Icon(Icons.access_time, color: Colors.grey, size: 16.h), Icon(Icons.access_time, color: contentColor, size: 16.h),
SizedBox(width: 8.w), SizedBox(width: 8.w),
Expanded( Expanded(
child: Text( child: Text(
DateFormat( DateFormat(
'yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd HH:mm:ss',
).format(problem.creationTime), ).format(problem.creationTime),
style: TextStyle(fontSize: 12.sp), style: TextStyle(fontSize: 12.sp, color: contentColor),
// overflow: TextOverflow.ellipsis,
), ),
), ),
], ],
@ -93,20 +101,46 @@ class ProblemCard extends StatelessWidget {
Wrap( Wrap(
spacing: 8, spacing: 8,
children: [ children: [
problem.syncStatus == SyncStatus.synced ...problem.isDeleted
? TDTag('已上传', isLight: true, theme: TDTagTheme.success) ? [
: TDTag('未上传', isLight: true, theme: TDTagTheme.danger), TDTag(
problem.bindData != null && problem.bindData!.isNotEmpty '已删除',
? TDTag('已绑定', isLight: true, theme: TDTagTheme.primary) theme: TDTagTheme.danger,
: TDTag( textColor: isDeleted ? Colors.grey[700] : null,
'未绑定', backgroundColor: isDeleted
isLight: true, ? Colors.grey[400]
theme: TDTagTheme.warning, : null,
), ),
]
: [
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(), const Spacer(),
_buildBottomActions(), // _buildBottomActions(isDeleted),
], ],
), ),
SizedBox(height: 8.h), SizedBox(height: 8.h),
@ -116,18 +150,70 @@ class ProblemCard extends StatelessWidget {
); );
} }
Widget _buildBottomActions() { Widget _buildImageWidget(bool isDeleted) {
return AspectRatio(
aspectRatio: 1, //
child: _buildImageContent(isDeleted),
);
}
Widget _buildImageContent(bool isDeleted) {
//
if (problem.imageUrls.isEmpty || problem.imageUrls[0].localPath.isEmpty) {
//
return Image.asset(
'assets/images/problem_preview.png',
fit: BoxFit.cover, // 使 cover
color: isDeleted ? Colors.grey[500] : null,
colorBlendMode: isDeleted ? BlendMode.saturation : null,
);
}
final String imagePath = problem.imageUrls[0].localPath;
//
final File imageFile = File(imagePath);
if (!imageFile.existsSync()) {
//
return Image.asset(
'assets/images/problem_preview.png',
fit: BoxFit.cover,
color: isDeleted ? Colors.grey[500] : null,
colorBlendMode: isDeleted ? BlendMode.saturation : null,
);
}
// 使 Image.file
return Image.file(
imageFile,
fit: BoxFit.cover, // 使 cover
color: isDeleted ? Colors.grey[500] : null,
colorBlendMode: isDeleted ? BlendMode.saturation : null,
errorBuilder: (context, error, stackTrace) {
//
return Image.asset(
'assets/images/problem_preview.png',
fit: BoxFit.cover,
color: isDeleted ? Colors.grey[500] : null,
colorBlendMode: isDeleted ? BlendMode.saturation : null,
);
},
);
}
Widget _buildBottomActions(bool isDeleted) {
switch (viewType) { switch (viewType) {
case ProblemCardViewType.buttons: case ProblemCardViewType.buttons:
return Row( return Row(
children: [ children: [
CustomButton( if (!isDeleted)
text: '修改', CustomButton(
onTap: () { text: '修改',
Get.toNamed(AppRoutes.problemForm, arguments: problem); onTap: () {
}, Get.toNamed(AppRoutes.problemForm, arguments: problem);
), },
SizedBox(width: 8.w), ),
if (!isDeleted) SizedBox(width: 8.w),
CustomButton( CustomButton(
text: '查看', text: '查看',
onTap: () { onTap: () {
@ -145,12 +231,14 @@ class ProblemCard extends StatelessWidget {
return Padding( return Padding(
padding: EdgeInsets.only(right: 16.w), padding: EdgeInsets.only(right: 16.w),
child: Checkbox( child: Checkbox(
value: isSelected, // 使 value: isSelected,
onChanged: (bool? value) { onChanged: isDeleted
if (value != null) { ? null
onChanged?.call(problem, value); : (bool? value) {
} if (value != null) {
}, onChanged?.call(problem, value);
}
},
), ),
); );
} }

Loading…
Cancel
Save