|
@@ -10,10 +10,11 @@ import 'package:cs_resources/theme/app_colors_theme.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
+import 'package:plugin_basic/constants/app_constant.dart';
|
|
|
import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
|
|
|
+import 'package:plugin_platform/engine/sp/sp_util.dart';
|
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
-import 'package:router/path/router_path.dart';
|
|
|
import 'package:shared/utils/log_utils.dart';
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
import 'package:widgets/dialog/app_custom_dialog.dart';
|
|
@@ -22,13 +23,10 @@ import 'package:widgets/my_checkbox_group.dart';
|
|
|
import '../garage/for_rent/for_rent_vm.dart';
|
|
|
import '../garage/for_sale/for_sale_vm.dart';
|
|
|
import '../garage/garagesale_post/garagesale_post_page.dart';
|
|
|
-import '../my_following/my_following_page.dart';
|
|
|
-import '../my_posts/my_posts_page.dart';
|
|
|
import 'community_page.dart';
|
|
|
import 'community_pageview_idx_data.dart';
|
|
|
import 'community_state.dart';
|
|
|
import 'foryou/foryou_vm.dart';
|
|
|
-import 'news/news_state.dart';
|
|
|
import 'newsfeed_post/newsfeed_post_page.dart';
|
|
|
|
|
|
part 'community_vm.g.dart';
|
|
@@ -38,39 +36,84 @@ class CommunityVm extends _$CommunityVm {
|
|
|
get topSectionsData => state.topSectionsData;
|
|
|
late CommonNewsFeedRespository commonNewsFeedRespositoryInstance;
|
|
|
late CommonGarageRespository commonGarageRespositoryInstance;
|
|
|
+ late Map<int, dynamic> providerMap = {};
|
|
|
|
|
|
- final Map<int, dynamic> providerMap = {};
|
|
|
+ bool _isSingleSelect = true;
|
|
|
+ List<Map<String, dynamic>> _currentSelectedGarageCategory = [];
|
|
|
|
|
|
-
|
|
|
+ Map<int, Map<String, dynamic>> _queryParams = {};
|
|
|
+
|
|
|
+
|
|
|
+ getCurrentQueryParams(String key) {
|
|
|
+ return _queryParams[state.currentPageViewIdx]?[key];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
ProviderBase getProvider(int index) {
|
|
|
return providerMap[index]!;
|
|
|
}
|
|
|
|
|
|
CommunityVmState initState() {
|
|
|
+ List<String> newsFeedTabsList = [
|
|
|
+ "News",
|
|
|
+ "Following",
|
|
|
+ "For You",
|
|
|
+ ];
|
|
|
+ List<String> garageSaleTabsList = [
|
|
|
+ "For Sale",
|
|
|
+ "For Rent",
|
|
|
+ ];
|
|
|
+
|
|
|
+ List<String> COMMUNITY_TABS_LIST = [...newsFeedTabsList];
|
|
|
+ COMMUNITY_TABS_LIST.addAll(garageSaleTabsList);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Log.d("COMMUNITY_TABS_LIST $COMMUNITY_TABS_LIST");
|
|
|
+
|
|
|
+ COMMUNITY_TABS_LIST.asMap().forEach((index, value) {
|
|
|
+ _queryParams[index] = {
|
|
|
+ 'keyword': null,
|
|
|
+ 'is_liked': null,
|
|
|
+ 'category_id': null,
|
|
|
+ 'category_name': null,
|
|
|
+ 'page_view_idx': index,
|
|
|
+ 'page_view_name': value,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
return CommunityVmState(
|
|
|
currentCategoryIdx: 0,
|
|
|
currentPageViewIdx: 0,
|
|
|
lastGarageTabIdx: 0,
|
|
|
lastNewsfeedTabIdx: 0,
|
|
|
- newsFeedTabsList: [
|
|
|
- "News",
|
|
|
- "Following",
|
|
|
- "For You",
|
|
|
- ],
|
|
|
- garageSaleTabsList: [
|
|
|
- "For Sale",
|
|
|
- "For Rent",
|
|
|
- ],
|
|
|
+ newsFeedTabsList: newsFeedTabsList,
|
|
|
+ garageSaleTabsList: garageSaleTabsList,
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
CommunityVmState build(){
|
|
|
+
|
|
|
|
|
|
commonNewsFeedRespositoryInstance = ref.read(commonNewsFeedRespositoryProvider);
|
|
|
commonGarageRespositoryInstance = ref.read(commonGarageRespositoryProvider);
|
|
|
final state = initState();
|
|
|
-
|
|
|
+
|
|
|
+ setCurrentPageViewIconStatus();
|
|
|
+ getPageViewVm();
|
|
|
+
|
|
|
+ Log.d("-------------community vm-------------build---------------------");
|
|
|
+ ref.onDispose((){
|
|
|
+ providerMap = {};
|
|
|
+ Log.d("-------------community vm-------------dispose---------------------");
|
|
|
+ });
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void getPageViewVm(){
|
|
|
+
|
|
|
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
|
|
|
|
|
CommunityPageViewIdxData.values.forEach((key, value) {
|
|
@@ -91,23 +134,26 @@ class CommunityVm extends _$CommunityVm {
|
|
|
providerMap[key] = ref.read(forrentVmProvider.notifier);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
});
|
|
|
- Log.d("-------------community vm-------------build---------------------");
|
|
|
- ref.onDispose((){
|
|
|
- Log.d("-------------community vm-------------dispose---------------------");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void setCurrentPageViewIconStatus(){
|
|
|
+ WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
|
|
+ Log.d("获取当前的导航栏 相关状态resMap444 ${providerMap[state.currentPageViewIdx]} ");
|
|
|
+ Map<String, dynamic> resMap = providerMap[state.currentPageViewIdx]?.getCurrentQueryParams(null)??{};
|
|
|
+ Log.d("获取当前的导航栏 相关状态resMap $resMap ");
|
|
|
+ _queryParams[state.currentPageViewIdx] = resMap;
|
|
|
});
|
|
|
- return state;
|
|
|
}
|
|
|
|
|
|
tabsRouterChange(){
|
|
|
+
|
|
|
Log.d("----tabsRouterChange---${tabsRouterKey.currentState?.controller?.activeIndex}-");
|
|
|
-
|
|
|
state = state.copyWith(currentPageViewIdx: tabsRouterKey.currentState?.controller?.activeIndex ?? 0);
|
|
|
+
|
|
|
+ setCurrentPageViewIconStatus();
|
|
|
+ getPageViewVm();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -119,6 +165,7 @@ class CommunityVm extends _$CommunityVm {
|
|
|
}else {
|
|
|
tabsRouter.setActiveIndex(state.newsFeedTabsList!.length + tabIndex);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -162,13 +209,7 @@ class CommunityVm extends _$CommunityVm {
|
|
|
}
|
|
|
|
|
|
|
|
|
- Future getGarageSaleCategoryOptions() async{
|
|
|
- final Map<String, dynamic> params = {};
|
|
|
- final result = await commonGarageRespositoryInstance.fetchGarageCateGoryList(params);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- handlerChooseGarageCategory(BuildContext context) async {
|
|
|
+ Future<List<Map<String, dynamic>>> getGarageSaleCategoryOptions() async{
|
|
|
List<Map<String, dynamic>> garageCategoryList = [
|
|
|
|
|
|
|
|
@@ -199,79 +240,173 @@ class CommunityVm extends _$CommunityVm {
|
|
|
|
|
|
|
|
|
];
|
|
|
-
|
|
|
|
|
|
try {
|
|
|
- final result = await getGarageSaleCategoryOptions();
|
|
|
- if(result.isSuccess){
|
|
|
- final listJson = result.getListJson();
|
|
|
-
|
|
|
- garageCategoryList = (listJson as List?)?.map((item) => item as Map<String, dynamic>).toList() ?? [];
|
|
|
- state = state.copyWith(
|
|
|
- garageCategoryList: garageCategoryList
|
|
|
- );
|
|
|
+
|
|
|
+ List<Map<String, dynamic>>? StorageCategoryList = SPUtil.getObjectList(
|
|
|
+ AppConstant.storageGarageCategoryList)?.cast<Map<String, dynamic>>();
|
|
|
|
|
|
- await DialogEngine.show(
|
|
|
- tag: "chooseGarageSaleCategory",
|
|
|
- position: DialogPosition.center,
|
|
|
- widget: AppCustomDialog(
|
|
|
- message: '',
|
|
|
- dialogWidth: MediaQuery.of(context).size.width * 0.8,
|
|
|
-
|
|
|
-
|
|
|
- isShowConfirmBtn: state.garageCategoryList!.length > 0 ? true: false,
|
|
|
- confirmTxt: "Ok",
|
|
|
- messageBuilder: (BuildContext context){
|
|
|
- return Container(
|
|
|
- color: context.appColors.textWhite,
|
|
|
- child: Column(
|
|
|
- mainAxisAlignment: MainAxisAlignment.start,
|
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
- children: state.garageCategoryList!.length > 0 ? [
|
|
|
- MyCheckboxGroup(
|
|
|
- isSingleSelect: false,
|
|
|
- labelStyle: const TextStyle(
|
|
|
- fontSize: 16,
|
|
|
- fontWeight: FontWeight.w500,
|
|
|
- ),
|
|
|
- items: state.garageCategoryList!,
|
|
|
- onChanged: (List<Map<String, dynamic>> selectedItems){
|
|
|
- Log.d("----MyCheckboxGroup onChanged $selectedItems");
|
|
|
- }
|
|
|
- )
|
|
|
- ]: [
|
|
|
- Container(
|
|
|
- child: CircularProgressIndicator(
|
|
|
- strokeWidth: 3,
|
|
|
- valueColor: AlwaysStoppedAnimation(context.appColors.textDarkGray),
|
|
|
- ),
|
|
|
- )
|
|
|
- ],
|
|
|
- ),
|
|
|
- );
|
|
|
- },
|
|
|
- isShowCancelBtn:false,
|
|
|
- confirmAction: (){
|
|
|
-
|
|
|
- },
|
|
|
- )
|
|
|
- );
|
|
|
+ if (StorageCategoryList != null && StorageCategoryList.isNotEmpty) {
|
|
|
+ Log.d("取StorageCategoryList 缓存: $StorageCategoryList ");
|
|
|
+ garageCategoryList = StorageCategoryList;
|
|
|
+ } else {
|
|
|
+ Map<String, dynamic> params = {};
|
|
|
+ final result = await commonGarageRespositoryInstance
|
|
|
+ .fetchGarageCateGoryList(params);
|
|
|
+ if (result.isSuccess) {
|
|
|
+ final listJson = result.getListJson();
|
|
|
+
|
|
|
+ garageCategoryList = (listJson as List?)
|
|
|
+ ?.map((item) => item as Map<String, dynamic>)
|
|
|
+ .toList() ?? [];
|
|
|
+
|
|
|
+ Log.d("设置StorageCategoryList 缓存");
|
|
|
+ SPUtil.putObjectList(
|
|
|
+ AppConstant.storageGarageCategoryList, garageCategoryList);
|
|
|
+ }
|
|
|
}
|
|
|
- }catch(error){
|
|
|
- Log.d("---------------- $error");
|
|
|
+ } catch(error){
|
|
|
+
|
|
|
}
|
|
|
+ return garageCategoryList;
|
|
|
+ }
|
|
|
+
|
|
|
+ handlerChooseGarageCategory(BuildContext context) async {
|
|
|
+ List<Map<String, dynamic>> garageCategoryList = await getGarageSaleCategoryOptions();
|
|
|
+
|
|
|
+ handlerShowChooseGarageCategoryDialog(context, garageCategoryList);
|
|
|
|
|
|
+ state = state.copyWith(
|
|
|
+ garageCategoryList: garageCategoryList
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> handlerShowChooseGarageCategoryDialog(BuildContext context, List<Map<String, dynamic>> garageCategoryList) async{
|
|
|
+ await DialogEngine.show(
|
|
|
+ tag: "chooseGarageSaleCategory",
|
|
|
+ position: DialogPosition.center,
|
|
|
+ widget: AppCustomDialog(
|
|
|
+ message: '',
|
|
|
+ dialogWidth: MediaQuery.of(context).size.width * 0.8,
|
|
|
+
|
|
|
+
|
|
|
+ isShowConfirmBtn: garageCategoryList!.length > 0 ? true: false,
|
|
|
+ confirmTxt: "Ok",
|
|
|
+ messageBuilder: (BuildContext context){
|
|
|
+ return Container(
|
|
|
+ color: context.appColors.textWhite,
|
|
|
+ child: Column(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.start,
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: garageCategoryList!.length > 0 ? [
|
|
|
+ MyCheckboxGroup(
|
|
|
+ isSingleSelect: _isSingleSelect,
|
|
|
+ labelStyle: const TextStyle(
|
|
|
+ fontSize: 16,
|
|
|
+ fontWeight: FontWeight.w500,
|
|
|
+ ),
|
|
|
+ items: garageCategoryList!,
|
|
|
+ defaultSelectedItems: [],
|
|
|
+ onChanged: (List<Map<String, dynamic>> selectedItems){
|
|
|
+ Log.d("----MyCheckboxGroup onChanged $selectedItems");
|
|
|
+ _currentSelectedGarageCategory = selectedItems;
|
|
|
+ }
|
|
|
+ )
|
|
|
+ ]: [
|
|
|
+ Container(
|
|
|
+ child: CircularProgressIndicator(
|
|
|
+ strokeWidth: 3,
|
|
|
+ valueColor: AlwaysStoppedAnimation(context.appColors.textDarkGray),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ isShowCancelBtn:false,
|
|
|
+ confirmAction: (){
|
|
|
+
|
|
|
+ Log.d("----点击了确定按钮");
|
|
|
+ int? categoryId;
|
|
|
+ if(_isSingleSelect){
|
|
|
+ if(_currentSelectedGarageCategory.length > 0){
|
|
|
+ categoryId = _currentSelectedGarageCategory[0]['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ providerMap[state.currentPageViewIdx]
|
|
|
+ ..setCurrentQueryParams({
|
|
|
+ "category_id": _queryParams?[state.currentPageViewIdx]?['categoryId'],
|
|
|
+ })
|
|
|
+ ..directRefresh();
|
|
|
+ },
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ handlerSearch(String value){
|
|
|
+ Log.d("community_vm 中 搜索 value: $value");
|
|
|
+ _queryParams?[state.currentPageViewIdx]?['keyword'] = value;
|
|
|
+ providerMap[state.currentPageViewIdx]
|
|
|
+ ..setCurrentQueryParams({
|
|
|
+ "keyword": _queryParams?[state.currentPageViewIdx]?['keyword'],
|
|
|
+ })
|
|
|
+ ..directRefresh();
|
|
|
}
|
|
|
|
|
|
|
|
|
handlerClickNavbarLikeBtn(BuildContext? context){
|
|
|
if(state.currentCategoryIdx ==0){
|
|
|
|
|
|
- ToastEngine.show("点击了 newsfeed like");
|
|
|
+
|
|
|
+
|
|
|
}else if(state.currentCategoryIdx == 1){
|
|
|
|
|
|
- ToastEngine.show("点击了 garagesale like");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _queryParams[state.currentPageViewIdx]?['is_liked'] = !(_queryParams?[state.currentPageViewIdx]?['is_liked']??false);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ handlerNestedScrollViewScroll();
|
|
|
+
|
|
|
+ providerMap[state.currentPageViewIdx]
|
|
|
+ ..setCurrentQueryParams({
|
|
|
+ "is_liked": _queryParams?[state.currentPageViewIdx]?['is_liked'],
|
|
|
+ })
|
|
|
+ ..directRefresh();
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ handlerNestedScrollViewScroll({double? outerOffset, double? innerOffset=0.0, bool? isOuterScrollAnimated=false, bool? isInnerScrollAnimated=false}){
|
|
|
+
|
|
|
+ if(outerOffset !=null){
|
|
|
+ if(isOuterScrollAnimated!){
|
|
|
+ extendedNestedScrollViewKey.currentState?.outerController.animateTo(
|
|
|
+ outerOffset,
|
|
|
+ duration: const Duration(seconds: 1),
|
|
|
+ curve: Curves.easeIn,
|
|
|
+ );
|
|
|
+ }else {
|
|
|
+ extendedNestedScrollViewKey.currentState?.outerController.jumpTo(
|
|
|
+ outerOffset,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(innerOffset !=null){
|
|
|
+ extendedNestedScrollViewKey.currentState?.innerPositions.forEach((position) {
|
|
|
+ if(isInnerScrollAnimated!){
|
|
|
+ position.animateTo(innerOffset,
|
|
|
+ duration: Duration(seconds: 1), curve: Curves.easeIn);
|
|
|
+ }else {
|
|
|
+ position.jumpTo(innerOffset);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -302,6 +437,7 @@ class CommunityVm extends _$CommunityVm {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
GaragesalePostPage.startInstance(type: type);
|
|
|
}
|
|
|
|