From 2ffb3b8c059fefd5333e62ebbfff62268a8a3e1c Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Thu, 13 Nov 2025 16:46:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(home):=20=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E5=88=B7=E6=96=B0=E7=BB=84=E4=BB=B6=E5=BA=93?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=88=B7=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 easy_refresh 组件替换为 pull_to_refresh - 更新 NearbyTab 和 RecommendTab 中的刷新控制器初始化方式 - 修改下拉刷新和上拉加载的回调方法命名和调用逻辑 - 调整刷新状态管理方法,如 refreshCompleted、loadComplete 等 - 更新 pubspec.yaml 添加 pull_to_refresh依赖并移除旧依赖配置 -优化刷新 Header 和 Footer 的提示文本显示效果 - 调整 SmartRefresher 的启用选项和物理滚动行为配置 --- lib/pages/home/nearby_tab.dart | 42 ++++++++++++++++++------------- lib/pages/home/recommend_tab.dart | 42 ++++++++++++++++++------------- pubspec.lock | 8 ++++++ pubspec.yaml | 1 + 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/lib/pages/home/nearby_tab.dart b/lib/pages/home/nearby_tab.dart index e0d0464..99a534d 100644 --- a/lib/pages/home/nearby_tab.dart +++ b/lib/pages/home/nearby_tab.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:easy_refresh/easy_refresh.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:dating_touchme_app/controller/home/home_controller.dart'; import 'package:dating_touchme_app/model/home/marriage_data.dart'; import 'package:dating_touchme_app/pages/home/content_card.dart'; @@ -16,15 +16,12 @@ class NearbyTab extends StatefulWidget { class _NearbyTabState extends State with AutomaticKeepAliveClientMixin { final HomeController controller = Get.find(); - late final EasyRefreshController _refreshController; + late final RefreshController _refreshController; @override void initState() { super.initState(); - _refreshController = EasyRefreshController( - controlFinishRefresh: true, - controlFinishLoad: true, - ); + _refreshController = RefreshController(initialRefresh: false); } @override @@ -46,46 +43,57 @@ class _NearbyTabState extends State final bool isLoading = controller.nearbyIsLoading.value; final bool hasMore = controller.nearbyHasMore.value; - return EasyRefresh( + return SmartRefresher( controller: _refreshController, - header: MaterialHeader(backgroundColor: Colors.red.withOpacity(0.9)), - footer: MaterialFooter(backgroundColor: Colors.red.withOpacity(0.9)), + enablePullDown: true, + enablePullUp: true, + header: const ClassicHeader( + refreshingText: '正在刷新...', + completeText: '刷新完成', + idleText: '下拉刷新', + releaseText: '释放刷新', + ), + footer: ClassicFooter( + idleText: '上拉加载', + loadingText: '正在加载...', + noDataText: '没有更多数据', + canLoadingText: '释放加载', + ), // 下拉刷新 onRefresh: () async { print('同城列表下拉刷新被触发'); try { await controller.refreshNearbyData(); - _refreshController.finishRefresh(IndicatorResult.success); + _refreshController.refreshCompleted(); print('同城列表刷新完成'); } catch (e) { print('同城列表刷新失败: $e'); - _refreshController.finishRefresh(IndicatorResult.fail); + _refreshController.refreshFailed(); } }, // 上拉加载更多 - onLoad: () async { + onLoading: () async { print('同城列表上拉加载被触发, hasMore: $hasMore'); if (hasMore && controller.nearbyHasMore.value) { try { await controller.loadNearbyMoreData(); // 完成加载,根据是否有更多数据决定 if (controller.nearbyHasMore.value) { - _refreshController.finishLoad(IndicatorResult.success); + _refreshController.loadComplete(); print('同城列表加载更多成功'); } else { - _refreshController.finishLoad(IndicatorResult.noMore); + _refreshController.loadNoData(); print('同城列表没有更多数据了'); } } catch (e) { print('同城列表加载更多失败: $e'); - _refreshController.finishLoad(IndicatorResult.fail); + _refreshController.loadFailed(); } } else { - _refreshController.finishLoad(IndicatorResult.noMore); + _refreshController.loadNoData(); print('同城列表没有更多数据'); } }, - // EasyRefresh 的 child 必须始终是可滚动的 Widget child: ListView.separated( // 关键:始终允许滚动,即使内容不足 physics: const AlwaysScrollableScrollPhysics( diff --git a/lib/pages/home/recommend_tab.dart b/lib/pages/home/recommend_tab.dart index 20b05b3..d906b31 100644 --- a/lib/pages/home/recommend_tab.dart +++ b/lib/pages/home/recommend_tab.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:easy_refresh/easy_refresh.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:dating_touchme_app/controller/home/home_controller.dart'; import 'package:dating_touchme_app/model/home/marriage_data.dart'; import 'package:dating_touchme_app/pages/home/content_card.dart'; @@ -16,15 +16,12 @@ class RecommendTab extends StatefulWidget { class _RecommendTabState extends State with AutomaticKeepAliveClientMixin { final HomeController controller = Get.find(); - late final EasyRefreshController _refreshController; + late final RefreshController _refreshController; @override void initState() { super.initState(); - _refreshController = EasyRefreshController( - controlFinishRefresh: true, - controlFinishLoad: true, - ); + _refreshController = RefreshController(initialRefresh: false); } @override @@ -46,46 +43,57 @@ class _RecommendTabState extends State final bool isLoading = controller.recommendIsLoading.value; final bool hasMore = controller.recommendHasMore.value; - return EasyRefresh( + return SmartRefresher( controller: _refreshController, - header: MaterialHeader(backgroundColor: Colors.red.withOpacity(0.9)), - footer: MaterialFooter(backgroundColor: Colors.red.withOpacity(0.9)), + enablePullDown: true, + enablePullUp: true, + header: const ClassicHeader( + refreshingText: '正在刷新...', + completeText: '刷新完成', + idleText: '下拉刷新', + releaseText: '释放刷新', + ), + footer: ClassicFooter( + idleText: '上拉加载', + loadingText: '正在加载...', + noDataText: '没有更多数据', + canLoadingText: '释放加载', + ), // 下拉刷新 onRefresh: () async { print('推荐列表下拉刷新被触发'); try { await controller.refreshRecommendData(); - _refreshController.finishRefresh(IndicatorResult.success); + _refreshController.refreshCompleted(); print('推荐列表刷新完成'); } catch (e) { print('推荐列表刷新失败: $e'); - _refreshController.finishRefresh(IndicatorResult.fail); + _refreshController.refreshFailed(); } }, // 上拉加载更多 - onLoad: () async { + onLoading: () async { print('推荐列表上拉加载被触发, hasMore: $hasMore'); if (hasMore && controller.recommendHasMore.value) { try { await controller.loadRecommendMoreData(); // 完成加载,根据是否有更多数据决定 if (controller.recommendHasMore.value) { - _refreshController.finishLoad(IndicatorResult.success); + _refreshController.loadComplete(); print('推荐列表加载更多成功'); } else { - _refreshController.finishLoad(IndicatorResult.noMore); + _refreshController.loadNoData(); print('推荐列表没有更多数据了'); } } catch (e) { print('推荐列表加载更多失败: $e'); - _refreshController.finishLoad(IndicatorResult.fail); + _refreshController.loadFailed(); } } else { - _refreshController.finishLoad(IndicatorResult.noMore); + _refreshController.loadNoData(); print('推荐列表没有更多数据'); } }, - // EasyRefresh 的 child 必须始终是可滚动的 Widget child: ListView.separated( // 关键:始终允许滚动,即使内容不足 physics: const AlwaysScrollableScrollPhysics( diff --git a/pubspec.lock b/pubspec.lock index 78bcaf9..1f3099d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1157,6 +1157,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.5.0" + pull_to_refresh: + dependency: "direct main" + description: + name: pull_to_refresh + sha256: bbadd5a931837b57739cf08736bea63167e284e71fb23b218c8c9a6e042aad12 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" rational: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index db85418..178247a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -66,6 +66,7 @@ dependencies: fluwx: ^5.7.5 tobias: ^5.3.1 agora_rtc_engine: ^6.5.3 + pull_to_refresh: ^2.0.0 dev_dependencies: flutter_test: From bd84da1f378a9dfa1597476480df46e3eb43e428 Mon Sep 17 00:00:00 2001 From: ZHR007 Date: Thu, 13 Nov 2025 17:01:33 +0800 Subject: [PATCH 2/2] no message --- lib/controller/mine/auth_controller.dart | 9 +++- lib/controller/mine/user_controller.dart | 21 ++++++-- lib/extension/router_service.dart | 62 ++++++++++++++++++++++++ lib/model/mine/user_data.dart | 50 +++++++++---------- lib/pages/main/main_page.dart | 3 +- lib/pages/mine/auth_center_page.dart | 6 ++- lib/pages/mine/mine_page.dart | 3 ++ 7 files changed, 122 insertions(+), 32 deletions(-) create mode 100644 lib/extension/router_service.dart diff --git a/lib/controller/mine/auth_controller.dart b/lib/controller/mine/auth_controller.dart index 9c7dfa8..33e5a4d 100644 --- a/lib/controller/mine/auth_controller.dart +++ b/lib/controller/mine/auth_controller.dart @@ -74,6 +74,11 @@ class AuthController extends GetxController { return id[17].toUpperCase() == checkCode; } + void changeAuth(int index){ + AuthCard card = dataList.firstWhere((item) => item.index == index); + card.authed = true; + } + Future startAuthing() async { if (name.value.isEmpty) { SmartDialog.showToast('请输入姓名'); @@ -103,7 +108,7 @@ class AuthController extends GetxController { if (response.data.isSuccess) { GlobalData().userData?.realAuth = true; SmartDialog.showToast('认证成功'); - Get.back(result: {'index': 3}); + Get.back(result: 3); } else { SmartDialog.showToast(response.data.message); } @@ -120,7 +125,7 @@ class AuthCard { final String title; final String desc; final int index; - final bool authed; + bool authed; AuthCard({ required this.desc, diff --git a/lib/controller/mine/user_controller.dart b/lib/controller/mine/user_controller.dart index 045fe50..b9d8d4c 100644 --- a/lib/controller/mine/user_controller.dart +++ b/lib/controller/mine/user_controller.dart @@ -75,6 +75,16 @@ class UserController extends GetxController { final response = await _userApi.getMarriageInformationDetail(); if (response.data.isSuccess) { // 检查data是否为null或者是空对象 + print(78111); + if(response.data.data == null){ + if(isMain){ + SmartDialog.showToast('转到完善信息'); + Get.to(() => UserInfoPage()); + } else { + Get.offAll(() => UserInfoPage()); + } + return; + } final information = response.data.data!; if (information.id.isNotEmpty) { final result = await _userApi.getCertificationList(information.id); @@ -83,16 +93,21 @@ class UserController extends GetxController { information.realAuth = record.status == 1; } GlobalData().userData = information; + print(95111); + print(GlobalData().userData); if (information.id.isEmpty || information.genderCode.isNaN || information.birthYear == null) { //跳转到完善信息 SmartDialog.showToast('转到完善信息'); // 导航到完善信息页面 - Get.offAll(() => UserInfoPage()); + if(isMain){ + SmartDialog.showToast('转到完善信息'); + Get.to(() => UserInfoPage()); + } else { + Get.offAll(() => UserInfoPage()); + } } else if(!isMain){ Get.offAll(MainPage()); } - } else { - // 获取婚姻信息失败不影响登录流程 } } catch (e) { // 获取婚姻信息失败不影响登录流程 diff --git a/lib/extension/router_service.dart b/lib/extension/router_service.dart new file mode 100644 index 0000000..d16e7f8 --- /dev/null +++ b/lib/extension/router_service.dart @@ -0,0 +1,62 @@ +// 路由拦截服务 +import 'package:dating_touchme_app/controller/global.dart'; +import 'package:get/get.dart'; + +import '../pages/mine/user_info_page.dart'; + +class RouteGuardService extends GetxService { + + static RouteGuardService get to => Get.find(); + + // 带认证检查的跳转 + Future toWithAuth(dynamic page, dynamic arguments) async { + bool checked = false; + if (GlobalData().userData != null) { + final information = GlobalData().userData!; + if(information.id.isNotEmpty && information.birthYear != null){ + checked = true; + } + } + if(!checked){ + final result = await Get.to(() => UserInfoPage()); + if (result != true) { + // return null; + } + return null; + } + return Get.to(() => page, arguments: arguments); + } + + // 带权限检查的跳转 + // Future toWithRole(dynamic page, String requiredRole) async { + // // 先检查登录 + // if (!await _checkAuth()) return null; + // + // // 再检查权限 + // if (!AuthService.to.hasRole(requiredRole)) { + // Get.snackbar('权限不足', '需要$requiredRole权限'); + // return null; + // } + // + // return Get.to(() => page); + // } + + // VIP 功能跳转 + // Future toWithVIP(dynamic page) async { + // if (!await _checkAuth()) return null; + // + // if (!AuthService.to.isVIP.value) { + // final result = await Get.to(() => VIPPurchasePage()); + // if (result != true) return null; + // } + // return Get.to(() => page); + // } + + // Future _checkAuth() async { + // if (!AuthService.to.isLoggedIn.value) { + // final result = await Get.to(() => LoginPage()); + // return result == true; + // } + // return true; + // } +} \ No newline at end of file diff --git a/lib/model/mine/user_data.dart b/lib/model/mine/user_data.dart index 0b9696b..9278ca8 100644 --- a/lib/model/mine/user_data.dart +++ b/lib/model/mine/user_data.dart @@ -9,55 +9,55 @@ class UserData { final String genderValue; final String? homeCountryCode; final String? homeCountry; - final String? provinceCode; + final int? provinceCode; final String? provinceName; - final String? cityCode; + final int? cityCode; final String? cityName; - final String? districtCode; + final int? districtCode; final String? districtName; final String? birthYear; final String? birthDate; - final String? constellationCode; + final int? constellationCode; final String? constellation; - final String? chineseZodiacCode; + final int? chineseZodiacCode; final String? chineseZodiac; - final String? height; - final String? weight; + final int? height; + final int? weight; final int? educationCode; final String? education; - final String? maritalStatusCode; + final int? maritalStatusCode; final String? maritalStatusName; - final String? minimumIncome; - final String? maximumIncome; - final String? incomeCode; + final int? minimumIncome; + final int? maximumIncome; + final int? incomeCode; final String? income; final String? describeInfo; - final String? domicilePlaceProvinceCode; + final int? domicilePlaceProvinceCode; final String? domicilePlaceProvinceName; - final String? domicilePlaceCityCode; + final int? domicilePlaceCityCode; final String? domicilePlaceCityName; - final String? nationCode; + final int? nationCode; final String? nation; - final String? bodilyFormCode; + final int? bodilyFormCode; final String? bodilyForm; - final String? accountTypeCode; + final int? accountTypeCode; final String? accountTypeName; - final String? nationalityCode; + final int? nationalityCode; final String? nationality; - final String? nativePlaceCode; + final int? nativePlaceCode; final String? nativePlaceName; - final String? industryCode; + final int? industryCode; final String? industry; - final String? occupationCode; + final int? occupationCode; final String? occupation; - final String? onlyChild; - final String? carPurchaseSituationCode; + final int? onlyChild; + final int? carPurchaseSituationCode; final String? carPurchaseSituation; - final String? propertyPermitsCode; + final int? propertyPermitsCode; final String? propertyPermits; - final String? hometownProvinceCode; + final int? hometownProvinceCode; final String? hometownProvinceName; - final String? hometownCityCode; + final int? hometownCityCode; final String? hometownCityName; bool? realAuth; diff --git a/lib/pages/main/main_page.dart b/lib/pages/main/main_page.dart index 41b25d8..92331c2 100644 --- a/lib/pages/main/main_page.dart +++ b/lib/pages/main/main_page.dart @@ -7,6 +7,7 @@ import 'package:get_storage/get_storage.dart'; import 'package:dating_touchme_app/controller/mine/user_controller.dart'; +import '../../extension/router_service.dart'; import '../../widget/double_tap_to_exit_widget.dart'; import '../discover/discover_page.dart'; import '../home/home_page.dart'; @@ -43,7 +44,7 @@ class _MainPageState extends State { // 初始化UserController并调用获取环信用户token的方法 final userController = Get.put(UserController()); userController.getHxUserToken(); - + Get.put(RouteGuardService()); // 检查token并调用获取婚姻信息详情的方法 checkTokenAndFetchMarriageInfo(); } diff --git a/lib/pages/mine/auth_center_page.dart b/lib/pages/mine/auth_center_page.dart index e3033bb..2239851 100644 --- a/lib/pages/mine/auth_center_page.dart +++ b/lib/pages/mine/auth_center_page.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../controller/mine/auth_controller.dart'; +import '../../extension/router_service.dart'; import 'edit_info_page.dart'; class AuthCenterPage extends StatelessWidget { @@ -115,9 +116,12 @@ class AuthCenterPage extends StatelessWidget { if(!item.authed){ if(item.index == 2){ Get.to(() => EditInfoPage()); + // Get.to(widget.path); } else if(item.index == 3){ final result = await Get.to(() => RealNamePage()); - print(result); + if(result > 0){ + controller.changeAuth(result); + } } } }); diff --git a/lib/pages/mine/mine_page.dart b/lib/pages/mine/mine_page.dart index a46ad45..a26b9e1 100644 --- a/lib/pages/mine/mine_page.dart +++ b/lib/pages/mine/mine_page.dart @@ -6,6 +6,8 @@ import 'package:dating_touchme_app/generated/assets.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; +import '../../extension/router_service.dart'; + class MinePage extends StatefulWidget { const MinePage({super.key}); @@ -239,6 +241,7 @@ class _BlockItemState extends State { onTap: (){ // context.pushNamed(widget.path); Get.to(widget.path); + // RouteGuardService.to.toWithAuth(widget.path, null); }, child: Container( width: 170.w,