|
@@ -1,241 +1,196 @@
|
|
-
|
|
|
|
-import 'package:cpt_community/modules/newsfeed/newsfeed_post/newsfeed_post_page.dart';
|
|
|
|
-import 'package:cs_resources/generated/assets.dart';
|
|
|
|
-import 'package:flutter/material.dart';
|
|
|
|
-import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
|
-import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
-import 'package:router/componentRouter/component_service_manager.dart';
|
|
|
|
-import 'package:router/ext/auto_router_extensions.dart';
|
|
|
|
-import 'package:router/path/router_path.dart';
|
|
|
|
-import 'package:shared/utils/color_utils.dart';
|
|
|
|
-import 'package:shared/utils/log_utils.dart';
|
|
|
|
-import 'package:auto_route/auto_route.dart';
|
|
|
|
-
|
|
|
|
-import '../../router/page/community_page_router.dart';
|
|
|
|
-import 'newsfeed_detail/newsfeed_detail_page.dart';
|
|
|
|
-import 'newsfeed_state.dart';
|
|
|
|
-import 'newsfeed_repository.dart';
|
|
|
|
-
|
|
|
|
-part 'newsfeed_vm.g.dart';
|
|
|
|
-
|
|
|
|
-@riverpod
|
|
|
|
-class NewsfeedVm extends _$NewsfeedVm {
|
|
|
|
- late NewsfeedRepository newsfeedRepository;
|
|
|
|
- NewsfeedState initState() {
|
|
|
|
- return NewsfeedState(
|
|
|
|
- useTag: 0, // 当前 大类目的 标签 (News Feed / Garage Sale)
|
|
|
|
- activeIndex: 0, // 当前tab 索引
|
|
|
|
- tabsList: [
|
|
|
|
- {
|
|
|
|
- 'title': 'News',
|
|
|
|
- 'icon': null,
|
|
|
|
- 'active': true,
|
|
|
|
- 'activeTitleColor': Colors.white,
|
|
|
|
- 'activeTitleFontSize': 16,
|
|
|
|
- 'activeTitleBackgroundColor': ColorUtils.string2Color("#4161D0"),
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'title': 'Following',
|
|
|
|
- 'icon': null,
|
|
|
|
- 'active': false,
|
|
|
|
- 'activeTitleColor': Colors.white,
|
|
|
|
- 'activeTitleFontSize': 16,
|
|
|
|
- 'activeTitleBackgroundColor': ColorUtils.string2Color("#4161D0"),
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'title': 'For You',
|
|
|
|
- 'icon': null,
|
|
|
|
- 'activeTitleColor': Colors.white,
|
|
|
|
- 'activeTitleFontSize': 16,
|
|
|
|
- 'activeTitleBackgroundColor': ColorUtils.string2Color("#4161D0"),
|
|
|
|
- }
|
|
|
|
- ],
|
|
|
|
- list: [
|
|
|
|
- {
|
|
|
|
- 'id':1,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'William Jefferson',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': ['https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg','https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg','https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg'],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': true,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':2,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'William fdsaf的飞洒发生的',
|
|
|
|
- 'isFollow': true,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': true,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':3,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'Fsjfkds dfsk',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': false,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':4,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'Fsjfkds dfsk',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': false,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':5,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'Fsjfkds dfsk',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': false,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':6,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': 'Fsjfkds dfsk',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': false,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 'id':7,
|
|
|
|
- 'avator': Assets.communityCamera,
|
|
|
|
- 'title': '放大发大水',
|
|
|
|
- 'isFollow': false,
|
|
|
|
- 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
- 'imageUrls': [],
|
|
|
|
- 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
- 'isLike': false,
|
|
|
|
- 'likeno': 12
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- @override
|
|
|
|
- NewsfeedState build(){
|
|
|
|
- // 引入数据仓库
|
|
|
|
- newsfeedRepository = ref.read(newsfeedRepositoryProvider);
|
|
|
|
- // 初始化状态
|
|
|
|
- NewsfeedState state = initState();
|
|
|
|
- return state;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 上拉加载
|
|
|
|
- Future onLoadData() async {
|
|
|
|
- Log.d("----newsfeed_vm-----initListData");
|
|
|
|
- // await Future.delayed(const Duration(seconds: 2));
|
|
|
|
- // if(state.list.length >= state.filterCount){
|
|
|
|
- // return;
|
|
|
|
- // }else {
|
|
|
|
- // int curPage = state.curPage + 1;
|
|
|
|
- // state = state.copyWith(curPage: curPage,);
|
|
|
|
- // 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 newsfeedRepository.fetchNewsfeedList(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 {
|
|
|
|
- Log.d("----property_news_vm-----refreshListData ");
|
|
|
|
-
|
|
|
|
- // await Future.delayed(const Duration(seconds: 2));
|
|
|
|
-
|
|
|
|
- state = state.copyWith(curPage: 1, pageSize: 10);
|
|
|
|
- // ref.invalidateSelf();
|
|
|
|
- // ref.invalidate(newsfeedVmProvider);
|
|
|
|
- getListData();
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 点击发布的按钮 跳转到发布的页面
|
|
|
|
- void handlerGotoPost(context){
|
|
|
|
- // ComponentServiceManager().communityService.startCommunityPage();
|
|
|
|
-
|
|
|
|
- // AutoRouter.of(context).pushNamed(RouterPath.newsFeedPost);
|
|
|
|
-
|
|
|
|
- NewsfeedPostPage.startInstance();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 点击tab (news 、 following 、 for you)
|
|
|
|
- void handlerClickTab(int index, item){
|
|
|
|
- // 修改当前tab 的索引
|
|
|
|
- state = state.copyWith(activeIndex: index);
|
|
|
|
- print("切换后新的 sate, ${state.tabsList}");
|
|
|
|
-
|
|
|
|
- // ref.invalidate(customTabsVmProvider);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 点击 like comments share
|
|
|
|
- void handlerClickActionBtn(String? actionStr, item){
|
|
|
|
- final id = item['id'];
|
|
|
|
- switch (actionStr) {
|
|
|
|
- case 'like':
|
|
|
|
- Log.d("点击了 点赞");
|
|
|
|
- handlerGotoDetail(id);
|
|
|
|
- break;
|
|
|
|
- case 'comments':
|
|
|
|
- Log.d("点击了 评论");
|
|
|
|
- handlerGotoDetail(id);
|
|
|
|
- break;
|
|
|
|
- case 'share':
|
|
|
|
- Log.d("点击了 分享");
|
|
|
|
- handlerGotoDetail(id);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 去详情页面
|
|
|
|
- void handlerGotoDetail(id){
|
|
|
|
- Log.d("去详情页面");
|
|
|
|
- appRouter.push(NewsfeedDetailPageRoute(id: id));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+import 'package:cs_resources/generated/assets.dart';
|
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
|
+import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
|
+import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
+import 'package:router/ext/auto_router_extensions.dart';
|
|
|
|
+import 'package:shared/utils/log_utils.dart';
|
|
|
|
+
|
|
|
|
+import '../../../router/page/community_page_router.dart';
|
|
|
|
+import '../garagesale_detail/garagesale_detail_page.dart';
|
|
|
|
+import 'for_rent_respository.dart';
|
|
|
|
+import 'for_rent_state.dart';
|
|
|
|
+
|
|
|
|
+part 'for_rent_vm.g.dart';
|
|
|
|
+
|
|
|
|
+@riverpod
|
|
|
|
+class ForrentVm extends _$ForrentVm {
|
|
|
|
+ late ForrentRepository ForrentRepositoryInstance;
|
|
|
|
+ ForrentState initState() {
|
|
|
|
+ return ForrentState(
|
|
|
|
+ list: [
|
|
|
|
+ {
|
|
|
|
+ 'id':1,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'William Jefferson',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': ['https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg','https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg','https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg'],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': true,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':2,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'William fdsaf的飞洒发生的',
|
|
|
|
+ 'isFollow': true,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': true,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':3,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'Fsjfkds dfsk',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': false,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':4,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'Fsjfkds dfsk',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': false,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':5,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'Fsjfkds dfsk',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': false,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':6,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': 'Fsjfkds dfsk',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': false,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 'id':7,
|
|
|
|
+ 'avator': Assets.communityCamera,
|
|
|
|
+ 'title': '放大发大水',
|
|
|
|
+ 'isFollow': false,
|
|
|
|
+ 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
|
|
|
|
+ 'imageUrls': [],
|
|
|
|
+ 'time': 'June 17,2016 at 7:23 p.m.',
|
|
|
|
+ 'isLike': false,
|
|
|
|
+ 'likeno': 12
|
|
|
|
+ },
|
|
|
|
+ ]
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ ForrentState build(){
|
|
|
|
+ // 引入数据仓库
|
|
|
|
+ ForrentRepositoryInstance = ref.read(forrentRepositoryProvider);
|
|
|
|
+ final state = initState();
|
|
|
|
+ Log.d("--------------------------build---------------------");
|
|
|
|
+
|
|
|
|
+ return state;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 设置当前的 tabsRouter 和 pageController
|
|
|
|
+ Future setTabsRouterAndPageController(dynamic tabsRouter, dynamic pageController) async{
|
|
|
|
+ Log.d("setTabsRouterAndPageController---:$tabsRouter");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// 上拉加载
|
|
|
|
+ Future onLoadData() async {
|
|
|
|
+ Log.d("----Forrent_vm-----initListData");
|
|
|
|
+ // await Future.delayed(const Duration(seconds: 2));
|
|
|
|
+ // if(state.list.length >= state.filterCount){
|
|
|
|
+ // return;
|
|
|
|
+ // }else {
|
|
|
|
+ // int curPage = state.curPage + 1;
|
|
|
|
+ // state = state.copyWith(curPage: curPage,);
|
|
|
|
+ // 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 ForrentRepositoryInstance.fetchForrentList(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 {
|
|
|
|
+ Log.d("----property_forrent_vm-----refreshListData ");
|
|
|
|
+
|
|
|
|
+ // await Future.delayed(const Duration(seconds: 2));
|
|
|
|
+
|
|
|
|
+ state = state.copyWith(curPage: 1, pageSize: 10);
|
|
|
|
+ // ref.invalidateSelf();
|
|
|
|
+ // ref.invalidate(ForrentVmProvider);
|
|
|
|
+ getListData();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 点击 like comments share
|
|
|
|
+ void handlerClickActionBtn(String? actionStr, item){
|
|
|
|
+ final id = item['id'];
|
|
|
|
+ switch (actionStr) {
|
|
|
|
+ case 'like':
|
|
|
|
+ Log.d("点击了 点赞");
|
|
|
|
+ handlerGotoDetail(id);
|
|
|
|
+ break;
|
|
|
|
+ case 'comments':
|
|
|
|
+ Log.d("点击了 评论");
|
|
|
|
+ handlerGotoDetail(id);
|
|
|
|
+ break;
|
|
|
|
+ case 'share':
|
|
|
|
+ Log.d("点击了 分享");
|
|
|
|
+ handlerGotoDetail(id);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 去详情页面
|
|
|
|
+ void handlerGotoDetail(id){
|
|
|
|
+ Log.d("去详情页面");
|
|
|
|
+ appRouter.push(GaragesaleDetailPageRoute(id: id, type: 'forrent'));
|
|
|
|
+ }
|
|
|
|
+}
|