From a25bf1ef1b5c81ce01cf863e6422212503f25736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=8C=AF=E5=8D=87?= <359059686@qq.com> Date: Sat, 8 Nov 2025 09:46:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20=E6=B2=A1=E6=9C=89=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E3=80=81=E9=97=AE=E9=A2=98=E6=97=B6=E6=97=A0=E6=B3=95=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/enterprise_list_page.dart | 77 +++++++++++-------- .../presentation/pages/problem_list_page.dart | 76 ++++++++++-------- 2 files changed, 92 insertions(+), 61 deletions(-) diff --git a/lib/app/features/enterprise/presentation/pages/enterprise_list_page.dart b/lib/app/features/enterprise/presentation/pages/enterprise_list_page.dart index bd9a4cd..4b04b33 100644 --- a/lib/app/features/enterprise/presentation/pages/enterprise_list_page.dart +++ b/lib/app/features/enterprise/presentation/pages/enterprise_list_page.dart @@ -180,37 +180,51 @@ class EnterpriseListPage extends GetView { /// 构建企业列表 Widget _buildEnterpriseList() { - // 使用 Obx 包裹以监听 controller 中所有 Rx 变量的变化 - return Obx(() { - // 在列表为空且仍在加载时显示加载指示器 - if (controller.isLoading.value) { - return const Center(child: CircularProgressIndicator()); - } - // 在加载完成但列表为空时显示提示信息 - if (controller.enterpriseList.isEmpty) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, + // 使用下拉刷新包裹列表 + return RefreshIndicator( + onRefresh: () async => controller.loadAndSyncEnterprises(), + child: Obx(() { + // 3. 在加载中状态,直接显示加载动画(此时不可滚动是合理的) + if (controller.isLoading.value && controller.enterpriseList.isEmpty) { + return const Center(child: CircularProgressIndicator()); + } + + // 4. 当列表为空时,将空状态提示也放入一个 ListView 中 + if (controller.enterpriseList.isEmpty) { + // 使用 ListView 包裹,并设置 AlwaysScrollableScrollPhysics + return ListView( + // [!!!] 关键:这行代码让 ListView 即使在内容不足一屏时也能滚动 + physics: const AlwaysScrollableScrollPhysics(), children: [ - Icon( - Icons.folder_off_outlined, - size: 60.sp, - color: Colors.grey[400], - ), - SizedBox(height: 16.h), - Text( - '没有找到相关企业', - style: TextStyle(fontSize: 16.sp, color: Colors.grey[600]), + // 为了让空状态提示在屏幕中居中,我们需要计算一下它的高度 + SizedBox( + // 获取父容器(Expanded)的高度 + height: Get.height * 0.5, // 可以根据实际情况调整这个高度 + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.folder_off_outlined, + size: 60.sp, + color: Colors.grey[400], + ), + SizedBox(height: 16.h), + Text( + '没有找到相关企业', + style: TextStyle( + fontSize: 16.sp, + color: Colors.grey[600], + ), + ), + ], + ), + ), ), ], - ), - ); - } - - // 使用下拉刷新包裹列表 - return RefreshIndicator( - onRefresh: () async => controller.loadAndSyncEnterprises(), - child: ListView.builder( + ); + } + return ListView.builder( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), itemCount: controller.enterpriseList.length, itemBuilder: (context, index) { @@ -296,8 +310,9 @@ class EnterpriseListPage extends GetView { ), ); }, - ), - ); - }); + ); + }), + ); + // }); } } diff --git a/lib/app/features/problem/presentation/pages/problem_list_page.dart b/lib/app/features/problem/presentation/pages/problem_list_page.dart index da4fa36..ecaec0a 100644 --- a/lib/app/features/problem/presentation/pages/problem_list_page.dart +++ b/lib/app/features/problem/presentation/pages/problem_list_page.dart @@ -273,37 +273,52 @@ class ProblemListPage extends GetView { /// 构建问题列表 Widget _buildEnterpriseList() { - // 使用 Obx 包裹以监听 controller 中所有 Rx 变量的变化 - return Obx(() { - // 在列表为空且仍在加载时显示加载指示器 - if (controller.isLoading.value) { - return const Center(child: CircularProgressIndicator()); - } - // 在加载完成但列表为空时显示提示信息 - if (controller.problemList.isEmpty) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, + // 使用下拉刷新包裹列表 + return RefreshIndicator( + onRefresh: () async => controller.loadAndSyncProblems(), + child: Obx(() { + // 3. 在加载中状态,直接显示加载动画(此时不可滚动是合理的) + if (controller.isLoading.value && controller.enterpriseList.isEmpty) { + return const Center(child: CircularProgressIndicator()); + } + + // 4. 当列表为空时,将空状态提示也放入一个 ListView 中 + if (controller.enterpriseList.isEmpty) { + // 使用 ListView 包裹,并设置 AlwaysScrollableScrollPhysics + return ListView( + // [!!!] 关键:这行代码让 ListView 即使在内容不足一屏时也能滚动 + physics: const AlwaysScrollableScrollPhysics(), children: [ - Icon( - Icons.folder_off_outlined, - size: 60.sp, - color: Colors.grey[400], - ), - SizedBox(height: 16.h), - Text( - '没有找到相关问题', - style: TextStyle(fontSize: 16.sp, color: Colors.grey[600]), + // 为了让空状态提示在屏幕中居中,我们需要计算一下它的高度 + SizedBox( + // 获取父容器(Expanded)的高度 + height: Get.height * 0.5, // 可以根据实际情况调整这个高度 + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.folder_off_outlined, + size: 60.sp, + color: Colors.grey[400], + ), + SizedBox(height: 16.h), + Text( + '没有找到相关问题', + style: TextStyle( + fontSize: 16.sp, + color: Colors.grey[600], + ), + ), + ], + ), + ), ), ], - ), - ); - } + ); + } - // 使用下拉刷新包裹列表 - return RefreshIndicator( - onRefresh: () async => controller.loadAndSyncProblems(), - child: ListView.builder( + return ListView.builder( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), itemCount: controller.problemList.length, itemBuilder: (context, index) { @@ -388,8 +403,9 @@ class ProblemListPage extends GetView { ), ); }, - ), - ); - }); + ); + }), + ); + // }); } }