From 5020451a84b1c3c4830362fe1758286b68f5e05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=8C=AF=E5=8D=87?= <359059686@qq.com> Date: Tue, 26 Aug 2025 08:45:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=E9=97=AE=E9=A2=98=E9=A1=B5?= =?UTF-8?q?=E6=82=AC=E6=B5=AE=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/problem/views/problem_page.dart | 118 +++++++++++--------- 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/lib/modules/problem/views/problem_page.dart b/lib/modules/problem/views/problem_page.dart index 7ef64d3..1173dbc 100644 --- a/lib/modules/problem/views/problem_page.dart +++ b/lib/modules/problem/views/problem_page.dart @@ -1,4 +1,3 @@ -// problem_page.dart import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; @@ -8,12 +7,11 @@ import 'package:problem_check_system/modules/problem/views/widgets/date_picker_b import 'package:problem_check_system/modules/problem/views/widgets/problem_card.dart'; import 'package:problem_check_system/modules/problem/views/problem_form_page.dart'; -class ProblemPage extends StatelessWidget { +class ProblemPage extends GetView { const ProblemPage({super.key}); @override Widget build(BuildContext context) { - final ProblemController problemController = Get.find(); return DefaultTabController( initialIndex: 0, length: 2, @@ -74,58 +72,44 @@ class ProblemPage extends StatelessWidget { ), ), Expanded( - child: Stack( - children: [ - Obx(() { - if (problemController.isLoading.value) { - return Center( - child: CircularProgressIndicator(), - ); + child: Obx(() { + if (controller.isLoading.value) { + return Center(child: CircularProgressIndicator()); + } + + return ListView.builder( + // +1 是为了在列表末尾添加一个额外的“空”项 + itemCount: controller.problems.length + 1, + itemBuilder: (context, index) { + // 如果是最后一个“空”项,返回一个 SizedBox + if (index == controller.problems.length) { + return SizedBox(height: 79.5.h); } - return ListView.builder( - itemCount: problemController.problems.length, - itemBuilder: (context, index) { - final problem = - problemController.problems[index]; - return _buildSwipeableProblemCard( - problem, - problemController, - ); - }, + // 否则,返回正常的列表项 + final problem = controller.problems[index]; + return _buildSwipeableProblemCard( + problem, + controller, ); - }), - Positioned( - bottom: 5.h, - right: 160.5.w, - child: FloatingActionButton( - heroTag: "123", - onPressed: () { - Get.to(() => ProblemFormPage()); - }, - shape: CircleBorder(), - backgroundColor: Colors.blue[300], - foregroundColor: Colors.white, - child: const Icon(Icons.add), - ), - ), - ], - ), + }, + ); + }), ), ], ), Obx(() { - if (problemController.isLoading.value) { + if (controller.isLoading.value) { return Center(child: CircularProgressIndicator()); } return ListView.builder( - itemCount: problemController.problems.length, + itemCount: controller.problems.length, itemBuilder: (context, index) { - final problem = problemController.problems[index]; + final problem = controller.problems[index]; return _buildSwipeableProblemCard( problem, - problemController, + controller, viewType: ProblemCardViewType.checkbox, ); }, @@ -137,20 +121,46 @@ class ProblemPage extends StatelessWidget { ], ), ), - floatingActionButton: Obx(() { - final bool isOnline = problemController.isOnline.value; - return FloatingActionButton( - heroTag: "abc", - onPressed: isOnline - ? () => problemController.uploadAllUnuploaded() - : null, - foregroundColor: Colors.white, - backgroundColor: isOnline ? Colors.red[300] : Colors.grey[400], - child: Icon( - isOnline ? Icons.file_upload_outlined : Icons.cloud_off_outlined, + floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, + floatingActionButton: Stack( + children: [ + Align( + alignment: Alignment.bottomCenter, + child: FloatingActionButton( + heroTag: "btn_add", + onPressed: () { + Get.to(() => ProblemFormPage()); + }, + shape: CircleBorder(), + backgroundColor: Colors.blue[300], + foregroundColor: Colors.white, + child: const Icon(Icons.add), + ), ), - ); - }), + Positioned( + bottom: 56.h, // 设置距离底部100像素 + right: 27.w, // 设置距离右侧16像素(通常的浮动按钮默认位置) + child: Obx(() { + final bool isOnline = controller.isOnline.value; + return FloatingActionButton( + heroTag: "btn_upload", + onPressed: isOnline + ? () => controller.uploadAllUnuploaded() + : null, + foregroundColor: Colors.white, + backgroundColor: isOnline + ? Colors.red[300] + : Colors.grey[400], + child: Icon( + isOnline + ? Icons.file_upload_outlined + : Icons.cloud_off_outlined, + ), + ); + }), + ), + ], + ), ), ); }