|
@@ -4,6 +4,8 @@ import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:router/ext/auto_router_extensions.dart';
|
|
import 'package:router/ext/auto_router_extensions.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
|
|
+import 'package:widgets/load_state_layout.dart';
|
|
|
|
+import 'package:widgets/widget_export.dart';
|
|
|
|
|
|
import '../../../router/page/community_page_router.dart';
|
|
import '../../../router/page/community_page_router.dart';
|
|
import '../garagesale_detail/garagesale_detail_page.dart';
|
|
import '../garagesale_detail/garagesale_detail_page.dart';
|
|
@@ -15,76 +17,17 @@ part 'for_sale_vm.g.dart';
|
|
@riverpod
|
|
@riverpod
|
|
class ForsaleVm extends _$ForsaleVm {
|
|
class ForsaleVm extends _$ForsaleVm {
|
|
late ForsaleRepository ForsaleRepositoryInstance;
|
|
late ForsaleRepository ForsaleRepositoryInstance;
|
|
|
|
+ bool _needShowPlaceholder = true; //是否展示LoadingView
|
|
|
|
+
|
|
|
|
+ // Refresh 控制器
|
|
|
|
+ final EasyRefreshController refreshController = EasyRefreshController(
|
|
|
|
+ controlFinishRefresh: true, //允许刷新
|
|
|
|
+ controlFinishLoad: true, //允许加载
|
|
|
|
+ );
|
|
|
|
+
|
|
ForsaleState initState() {
|
|
ForsaleState initState() {
|
|
return ForsaleState(
|
|
return ForsaleState(
|
|
- list: [
|
|
|
|
- {
|
|
|
|
- 'id':1,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$66',
|
|
|
|
- 'isCollection': true,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':2,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$88',
|
|
|
|
- 'isCollection': false,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':3,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$66',
|
|
|
|
- 'isCollection': true,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':4,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$88',
|
|
|
|
- 'isCollection': false,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':5,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$66',
|
|
|
|
- 'isCollection': true,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':6,
|
|
|
|
- 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
|
- 'price': '\$88',
|
|
|
|
- 'isCollection': false,
|
|
|
|
- 'collection_num': 12,
|
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'publisher_avator': Assets.communityCamera
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
|
|
+ list: []
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -98,14 +41,24 @@ class ForsaleVm extends _$ForsaleVm {
|
|
return state;
|
|
return state;
|
|
}
|
|
}
|
|
|
|
|
|
- // 设置当前的 tabsRouter 和 pageController
|
|
|
|
- Future setTabsRouterAndPageController(dynamic tabsRouter, dynamic pageController) async{
|
|
|
|
- Log.d("setTabsRouterAndPageController---:$tabsRouter");
|
|
|
|
|
|
+
|
|
|
|
+ //刷新页面状态
|
|
|
|
+ void changeLoadingState(LoadState loadState, String? errorMsg) {
|
|
|
|
+ state = state.copyWith(
|
|
|
|
+ loadingState: loadState,
|
|
|
|
+ errorMessage: errorMsg
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 初始化页面数据
|
|
|
|
+ initPageData() {
|
|
|
|
+ Log.d("----for_sale_vm-----initPageData ${state.loadingState}");
|
|
|
|
+ onRefresh();
|
|
}
|
|
}
|
|
|
|
|
|
-// 上拉加载
|
|
|
|
- Future onLoadData() async {
|
|
|
|
- Log.d("----Forsale_vm-----initListData");
|
|
|
|
|
|
+ // 上拉加载 更多
|
|
|
|
+ Future loadMore() async {
|
|
|
|
+ Log.d("----for_sale_vm-----loadMore");
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
// if(state.list.length >= state.filterCount){
|
|
// if(state.list.length >= state.filterCount){
|
|
// return;
|
|
// return;
|
|
@@ -114,46 +67,147 @@ class ForsaleVm extends _$ForsaleVm {
|
|
// state = state.copyWith(curPage: curPage,);
|
|
// state = state.copyWith(curPage: curPage,);
|
|
// getListData();
|
|
// 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 ForsaleRepositoryInstance.fetchForsaleList(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");
|
|
|
|
- }
|
|
|
|
|
|
+ // 检查 curPage 是否为 null,并初始化为 1
|
|
|
|
+ int newCurPage = state.curPage ?? 1;
|
|
|
|
+ state = state.copyWith(curPage: ++newCurPage);
|
|
|
|
+ getListData();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// 下拉刷新
|
|
// 下拉刷新
|
|
- Future refreshListData() async {
|
|
|
|
- Log.d("----property_news_vm-----refreshListData ");
|
|
|
|
|
|
+ Future onRefresh() async {
|
|
|
|
+ Log.d("----forsale_vm-----onRefresh ");
|
|
|
|
|
|
// 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(ForsaleVmProvider);
|
|
|
|
|
|
+ // 重试请求
|
|
|
|
+ Future retryRequest() async {
|
|
|
|
+ state = state.copyWith(curPage: 1);
|
|
|
|
+ _needShowPlaceholder = true;
|
|
getListData();
|
|
getListData();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获取list 列表数据
|
|
|
|
+ Future getListData<T>() async {
|
|
|
|
+ if (_needShowPlaceholder) {
|
|
|
|
+ changeLoadingState(LoadState.State_Loading, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Log.d("for_sale加载listData数据---------------start--${state.curPage}---");
|
|
|
|
+ // 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;
|
|
|
|
+ // handleList(listResult.data?.rows);
|
|
|
|
+ // ToastEngine.show("获取数据成功");
|
|
|
|
+ // } else {
|
|
|
|
+ // errorMessage = listResult.errorMsg;
|
|
|
|
+ // changeLoadingState(LoadState.State_Error);
|
|
|
|
+ // 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,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$66',
|
|
|
|
+ 'isCollection': true,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':2,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$88',
|
|
|
|
+ 'isCollection': false,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':3,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$66',
|
|
|
|
+ 'isCollection': true,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':4,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$88',
|
|
|
|
+ 'isCollection': false,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':5,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$66',
|
|
|
|
+ 'isCollection': true,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':6,
|
|
|
|
+ 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
|
|
|
|
+ 'title': 'Electronic keyboard',
|
|
|
|
+ 'price': '\$88',
|
|
|
|
+ 'isCollection': false,
|
|
|
|
+ 'collection_num': 12,
|
|
|
|
+ 'publisher': 'William Jefferson',
|
|
|
|
+ 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'publisher_avator': Assets.communityCamera
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ if (state.curPage == 1) {
|
|
|
|
+ //刷新的方式
|
|
|
|
+ state = state.copyWith(list: listData);
|
|
|
|
+ refreshController.finishRefresh();
|
|
|
|
+ // //更新展示的状态
|
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
|
+ } else {
|
|
|
|
+ //加载更多
|
|
|
|
+ final allList = state.list;
|
|
|
|
+ allList.addAll(listData);
|
|
|
|
+ refreshController.finishLoad();
|
|
|
|
+ state = state.copyWith(list: allList);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ // 最后赋值
|
|
|
|
+ _needShowPlaceholder = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|