|
@@ -2,36 +2,30 @@ import 'package:plugin_platform/http/http_result.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
|
+import 'package:widgets/load_state_layout.dart';
|
|
|
|
+import 'package:widgets/widget_export.dart';
|
|
import '../page/property_news_state.dart';
|
|
import '../page/property_news_state.dart';
|
|
import '../repository/property_news_repository.dart';
|
|
import '../repository/property_news_repository.dart';
|
|
|
|
+
|
|
part 'property_news_vm.g.dart';
|
|
part 'property_news_vm.g.dart';
|
|
|
|
|
|
@riverpod
|
|
@riverpod
|
|
class PropertyNewsVm extends _$PropertyNewsVm {
|
|
class PropertyNewsVm extends _$PropertyNewsVm {
|
|
late PropertyNewsRepository propertyNewsRepository;
|
|
late PropertyNewsRepository propertyNewsRepository;
|
|
|
|
+
|
|
|
|
+ bool _needShowPlaceholder = true; //是否展示LoadingView
|
|
|
|
+
|
|
|
|
+ // Refresh 控制器
|
|
|
|
+ final EasyRefreshController refreshController = EasyRefreshController(
|
|
|
|
+ controlFinishRefresh: true, //允许刷新
|
|
|
|
+ controlFinishLoad: true, //允许加载
|
|
|
|
+ );
|
|
|
|
+
|
|
PropertyNewsState initState() {
|
|
PropertyNewsState initState() {
|
|
return PropertyNewsState(
|
|
return PropertyNewsState(
|
|
- curPage: 1,
|
|
|
|
- pageSize: 10,
|
|
|
|
list: [
|
|
list: [
|
|
- {
|
|
|
|
- "id": 1,
|
|
|
|
- "title": "fkladsfk fldask fldsakfllfkaslsd",
|
|
|
|
- "description": "fsklfdsk罚款乱收费上课了发送卡",
|
|
|
|
- "time": "2024-02-15 12:00:00",
|
|
|
|
- "isCollection": true,
|
|
|
|
- "pic": ""
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "id": 2,
|
|
|
|
- "title": "JHKFDSAJKjfkdsfjkasjkjklfajfkajifwoqirujweiqofjndsaikfniasdhfiasdhfiadshfifjadslfjkdlsafjlkadsj",
|
|
|
|
- "description": "oifosjf fjdskafj hjiwehfriohjfiash",
|
|
|
|
- "time": "2024-10-16 12:00:00",
|
|
|
|
- "isCollection": false,
|
|
|
|
- "pic": ""
|
|
|
|
- },
|
|
|
|
|
|
+
|
|
],
|
|
],
|
|
- filterCount: 2,
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -45,6 +39,14 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
return state;
|
|
return state;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //刷新页面状态
|
|
|
|
+ void changeLoadingState(LoadState loadState, String? errorMsg) {
|
|
|
|
+ state = state.copyWith(
|
|
|
|
+ loadingState: loadState,
|
|
|
|
+ errorMessage: errorMsg
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
// 初始化页面数据
|
|
// 初始化页面数据
|
|
initPageData() {
|
|
initPageData() {
|
|
Log.d("----property_news_vm-----initPageData");
|
|
Log.d("----property_news_vm-----initPageData");
|
|
@@ -62,48 +64,101 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
// state = state.copyWith(curPage: curPage,);
|
|
// state = state.copyWith(curPage: curPage,);
|
|
// getListData();
|
|
// getListData();
|
|
// }
|
|
// }
|
|
|
|
+ // 检查 curPage 是否为 null,并初始化为 1
|
|
|
|
+ int newCurPage = state.curPage ?? 1;
|
|
|
|
+ state = state.copyWith(curPage: ++newCurPage);
|
|
getListData();
|
|
getListData();
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取list 列表数据
|
|
|
|
- void getListData<T>() async {
|
|
|
|
- Log.d("加载listData数据---------------start-----");
|
|
|
|
- try {
|
|
|
|
- //请求网络
|
|
|
|
- Map<String, dynamic> params = {
|
|
|
|
- "curPage": state.curPage,
|
|
|
|
- "pageSize": state.pageSize,
|
|
|
|
- };
|
|
|
|
- Log.d("请求参数------$params");
|
|
|
|
- final result = await propertyNewsRepository.fetchPropertyNewsList(params);
|
|
|
|
- Log.d("请求完成结果------${result.data}");
|
|
|
|
- //校验成功失败
|
|
|
|
- if (result.isSuccess) {
|
|
|
|
- // state = state.copyWith(serverTime: result.data);
|
|
|
|
- state = state;
|
|
|
|
- ToastEngine.show("获取数据成功");
|
|
|
|
- } else {
|
|
|
|
- ToastEngine.show(result.errorMsg ?? "Network Load Error");
|
|
|
|
- }
|
|
|
|
- } catch (e) {
|
|
|
|
- ToastEngine.show("Error: $e");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
// 下拉刷新
|
|
// 下拉刷新
|
|
Future refreshListData() async {
|
|
Future refreshListData() async {
|
|
Log.d("----property_news_vm-----refreshListData ");
|
|
Log.d("----property_news_vm-----refreshListData ");
|
|
|
|
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
|
|
+ state = state.copyWith(curPage: 1);
|
|
|
|
+ getListData();
|
|
|
|
+ }
|
|
|
|
|
|
- state = state.copyWith(curPage: 1, pageSize: 10);
|
|
|
|
- // ref.invalidateSelf();
|
|
|
|
- // ref.invalidate(propertyNewsVmProvider);
|
|
|
|
|
|
+ // 重试请求
|
|
|
|
+ Future retryRequest() async {
|
|
|
|
+ state = state.copyWith(curPage: 1);
|
|
|
|
+ _needShowPlaceholder = true;
|
|
getListData();
|
|
getListData();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获取list 列表数据
|
|
|
|
+ void getListData<T>() async {
|
|
|
|
+ if (_needShowPlaceholder) {
|
|
|
|
+ changeLoadingState(LoadState.State_Loading, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Log.d("加载listData数据---------------start-----");
|
|
|
|
+ // try {
|
|
|
|
+ // //请求网络
|
|
|
|
+ // Map<String, dynamic> params = {
|
|
|
|
+ // "curPage": state.curPage,
|
|
|
|
+ // "pageSize": state.pageSize,
|
|
|
|
+ // };
|
|
|
|
+ // Log.d("请求参数------$params");
|
|
|
|
+ // final result = await propertyNewsRepository.fetchPropertyNewsList(params);
|
|
|
|
+ // Log.d("请求完成结果------${result.data}");
|
|
|
|
+ // //校验成功失败
|
|
|
|
+ // if (result.isSuccess) {
|
|
|
|
+ // // state = state.copyWith(serverTime: result.data);
|
|
|
|
+ // state = state;
|
|
|
|
+ // ToastEngine.show("获取数据成功");
|
|
|
|
+ // } else {
|
|
|
|
+ // ToastEngine.show(result.errorMsg ?? "Network Load Error");
|
|
|
|
+ // }
|
|
|
|
+ // } catch (e) {
|
|
|
|
+ // ToastEngine.show("Error: $e");
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
+ await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
|
+ final List<Map<String, dynamic>> listData = [
|
|
|
|
+ {
|
|
|
|
+ "id": 1,
|
|
|
|
+ "title": "fkladsfk fldask fldsakfllfkaslsd",
|
|
|
|
+ "description": "fsklfdsk罚款乱收费上课了发送卡",
|
|
|
|
+ "time": "2024-02-15 12:00:00",
|
|
|
|
+ "isCollection": true,
|
|
|
|
+ "pic": ""
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "id": 2,
|
|
|
|
+ "title": "JHKFDSAJKjfkdsfjkasjkjklfajfkajifwoqirujweiqofjndsaikfniasdhfiasdhfiadshfifjadslfjkdlsafjlkadsj",
|
|
|
|
+ "description": "oifosjf fjdskafj hjiwehfriohjfiash",
|
|
|
|
+ "time": "2024-10-16 12:00:00",
|
|
|
|
+ "isCollection": false,
|
|
|
|
+ "pic": ""
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ if (state.curPage == 1) {
|
|
|
|
+ //刷新的方式
|
|
|
|
+ state = state.copyWith(list: listData);
|
|
|
|
+ refreshController.finishRefresh();
|
|
|
|
+
|
|
|
|
+ //更新展示的状态
|
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
|
+ } else {
|
|
|
|
+ //加载更多
|
|
|
|
+ final allList = state.list;
|
|
|
|
+ allList.addAll(listData);
|
|
|
|
+ state.list.addAll(listData);
|
|
|
|
+
|
|
|
|
+ refreshController.finishLoad();
|
|
|
|
+
|
|
|
|
+ state = state.copyWith(list: allList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 最后赋值
|
|
|
|
+ _needShowPlaceholder = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
// 去新闻详情页
|
|
// 去新闻详情页
|
|
void goNewsDetail(String item) {
|
|
void goNewsDetail(String item) {
|
|
Log.d("goNewsDetail");
|
|
Log.d("goNewsDetail");
|