Quellcode durchsuchen

Merge remote-tracking branch 'origin/dev' into dev

liukai vor 2 Tagen
Ursprung
Commit
2ad8360ac7

+ 45 - 27
packages/cpt_property/lib/modules/ioan/property_ioan_page.dart

@@ -3,11 +3,13 @@ import 'package:cs_resources/generated/assets.dart';
 import 'package:cs_resources/theme/app_colors_theme.dart';
 import 'package:flutter/material.dart';
 import 'package:auto_route/auto_route.dart';
+import 'package:flutter_hooks/flutter_hooks.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
 import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:router/ext/auto_router_extensions.dart';
 import 'package:shared/utils/color_utils.dart';
 import 'package:widgets/ext/ex_widget.dart';
+import 'package:widgets/load_state_layout.dart';
 import 'package:widgets/my_button.dart';
 import 'package:widgets/my_load_image.dart';
 import 'package:widgets/my_text_view.dart';
@@ -362,6 +364,12 @@ class PropertyIoanPage extends HookConsumerWidget {
   @override
   Widget build(BuildContext context, WidgetRef ref) {
     final _vm = ref.read(propertyIoanVmProvider.notifier);
+    final state = ref.watch(propertyIoanVmProvider);
+
+    useEffect((){
+      _vm.initPageData();
+      return () {};
+    }, []);
 
     return Scaffold(
       backgroundColor: ColorUtils.string2Color("#F2F3F6"),
@@ -369,35 +377,45 @@ class PropertyIoanPage extends HookConsumerWidget {
       body: Column(
         children: [
           Expanded(
-            child: SingleChildScrollView(
-              scrollDirection: Axis.vertical,
-              physics: const BouncingScrollPhysics(),
-              clipBehavior: Clip.none,
-              child: Padding(
-                  padding: const EdgeInsets.only(left: 15,right: 15,top: 15),
-                  child: _buildCotentBox(context, ref, _vm),
-              )
+            child: LoadStateLayout(
+              state: state.loadingState,
+              errorMessage: state.errorMessage,
+              errorRetry: () {
+                _vm.retryRequest();
+              },
+              successWidget: SingleChildScrollView(
+                scrollDirection: Axis.vertical,
+                physics: const BouncingScrollPhysics(),
+                clipBehavior: Clip.none,
+                child: Padding(
+                    padding: const EdgeInsets.only(left: 15,right: 15,top: 15),
+                    child: _buildCotentBox(context, ref, _vm),
+                )
+              ),
             )
           ),
-          Container(
-            height: 50,
-            color: ColorUtils.string2Color('#4161D0'),
-            child: Row(
-              mainAxisAlignment: MainAxisAlignment.center,
-              children: [
-                // MyLoadImage(Assets.propertyIoanItemBg,width: 60,height: 50,),
-                const SizedBox(width: 10,),
-                MyTextView(
-                  "Request a Quote",
-                  fontSize: 16,
-                  textColor: Colors.white,
-                  isFontMedium: true,
-                ),
-              ],
-            ),
-          ).onTap((){
-            _vm.handlerRequestQuote(context);
-          })
+          Visibility(
+            visible: state.loadingState == LoadState.State_Success,
+            child: Container(
+              height: 50,
+              color: ColorUtils.string2Color('#4161D0'),
+              child: Row(
+                mainAxisAlignment: MainAxisAlignment.center,
+                children: [
+                  // MyLoadImage(Assets.propertyIoanItemBg,width: 60,height: 50,),
+                  const SizedBox(width: 10,),
+                  MyTextView(
+                    "Request a Quote",
+                    fontSize: 16,
+                    textColor: Colors.white,
+                    isFontMedium: true,
+                  ),
+                ],
+              ),
+            ).onTap((){
+              _vm.handlerRequestQuote(context);
+            }),
+          )
         ],
       ),
     );

+ 1 - 1
packages/cpt_property/lib/modules/ioan/property_ioan_repository.dart

@@ -60,7 +60,7 @@ class PropertyIoanRepository {
     if (result.isSuccess) {
       //重新赋值data或list
       final json = result.getDataJson();
-      var data = PropertyIoanState.fromJson(json!);
+      var data = PropertyIoanState.fromMap(json!);
       //重新赋值data或list
       return result.convert<PropertyIoanState>(data: data);
     }

+ 49 - 34
packages/cpt_property/lib/modules/ioan/property_ioan_state.dart

@@ -2,42 +2,32 @@
 
 import 'dart:convert';
 
-PropertyIoanState propertyIoanStateFromJson(String str) => PropertyIoanState.fromJson(json.decode(str));
-
-String propertyIoanStateToJson(PropertyIoanState data) => json.encode(data.toJson());
+import 'package:widgets/load_state_layout.dart';
 
 class PropertyIoanState {
-    PropertyIoanState({
-        required this.offerTextInfoList,
-        required this.lowestFloatingRate,
-        required this.othersOfferingPic,
-        required this.lowestFixedRate,
-        required this.othersOfferingInfoList,
-    });
-
-    List<dynamic> offerTextInfoList;
-    String lowestFloatingRate;
-    String othersOfferingPic;
-    String lowestFixedRate;
-    List<dynamic> othersOfferingInfoList;
-
-    factory PropertyIoanState.fromJson(Map<dynamic, dynamic> json) => PropertyIoanState(
-        offerTextInfoList: List<dynamic>.from(json["offerTextInfoList"].map((x) => x)),
-        lowestFloatingRate: json["lowestFloatingRate"],
-        othersOfferingPic: json["othersOfferingPic"],
-        lowestFixedRate: json["lowestFixedRate"],
-        othersOfferingInfoList: List<dynamic>.from(json["othersOfferingInfoList"].map((x) => x)),
-    );
+  //页面 LoadView 状态的展示
+  LoadState loadingState;
+  String? errorMessage;
 
-    Map<dynamic, dynamic> toJson() => {
-        "offerTextInfoList": List<dynamic>.from(offerTextInfoList.map((x) => x)),
-        "lowestFloatingRate": lowestFloatingRate,
-        "othersOfferingPic": othersOfferingPic,
-        "lowestFixedRate": lowestFixedRate,
-        "othersOfferingInfoList": List<dynamic>.from(othersOfferingInfoList.map((x) => x)),
-    };
+  List<dynamic> offerTextInfoList;
+  String lowestFloatingRate;
+  String othersOfferingPic;
+  String lowestFixedRate;
+  List<dynamic> othersOfferingInfoList;
 
-    PropertyIoanState copyWith({
+  PropertyIoanState({
+    this.loadingState = LoadState.State_Loading,
+    String? errorMessage,
+    required this.offerTextInfoList,
+    required this.lowestFloatingRate,
+    required this.othersOfferingPic,
+    required this.lowestFixedRate,
+    required this.othersOfferingInfoList,
+  });
+
+  PropertyIoanState copyWith({
+    LoadState? loadingState,
+    String? errorMessage,
     List<dynamic>? offerTextInfoList,
     String? lowestFloatingRate,
     String? othersOfferingPic,
@@ -45,12 +35,37 @@ class PropertyIoanState {
     List<dynamic>? othersOfferingInfoList,
   }) {
     return PropertyIoanState(
+      loadingState: loadingState ?? this.loadingState,
+      errorMessage: errorMessage ?? this.errorMessage,
       offerTextInfoList: offerTextInfoList ?? this.offerTextInfoList,
       lowestFloatingRate: lowestFloatingRate ?? this.lowestFloatingRate,
       othersOfferingPic: othersOfferingPic ?? this.othersOfferingPic,
       lowestFixedRate: lowestFixedRate ?? this.lowestFixedRate,
-      othersOfferingInfoList:
-          othersOfferingInfoList ?? this.othersOfferingInfoList,
+      othersOfferingInfoList: othersOfferingInfoList ?? this.othersOfferingInfoList,
+    );
+  }
+
+  Map<String, dynamic> toMap() {
+    return {
+      'loadingState': this.loadingState,
+      'errorMessage': this.errorMessage,
+      'offerTextInfoList': this.offerTextInfoList,
+      'lowestFloatingRate': this.lowestFloatingRate,
+      'othersOfferingPic': this.othersOfferingPic,
+      'lowestFixedRate': this.lowestFixedRate,
+      'othersOfferingInfoList': this.othersOfferingInfoList,
+    };
+  }
+
+  factory PropertyIoanState.fromMap(Map<String, dynamic> map) {
+    return PropertyIoanState(
+      loadingState: map['loadingState'] as LoadState,
+      errorMessage: map['errorMessage'] as String,
+      offerTextInfoList: map['offerTextInfoList'] as List<dynamic>,
+      lowestFloatingRate: map['lowestFloatingRate'] as String,
+      othersOfferingPic: map['othersOfferingPic'] as String,
+      lowestFixedRate: map['lowestFixedRate'] as String,
+      othersOfferingInfoList: map['othersOfferingInfoList'] as List<dynamic>,
     );
   }
 }

+ 40 - 0
packages/cpt_property/lib/modules/ioan/property_ioan_vm.dart

@@ -6,7 +6,9 @@ import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:riverpod_annotation/riverpod_annotation.dart';
 import 'package:shared/utils/color_utils.dart';
 import 'package:shared/utils/log_utils.dart';
+import 'package:widgets/load_state_layout.dart';
 import 'package:widgets/my_text_view.dart';
+import 'package:widgets/widget_export.dart';
 import '../../components/bottomDialog.dart';
 import './property_ioan_state.dart';
 
@@ -14,6 +16,15 @@ part 'property_ioan_vm.g.dart';
 
 @riverpod
 class PropertyIoanVm extends _$PropertyIoanVm {
+  bool _needShowPlaceholder = true; //是否展示LoadingView
+
+  // Refresh 控制器
+  final EasyRefreshController refreshController = EasyRefreshController(
+    controlFinishRefresh: true,  //允许刷新
+    controlFinishLoad: true,   //允许加载
+  );
+
+
   PropertyIoanState initState() {
     return PropertyIoanState(
         lowestFloatingRate: "3.79%",
@@ -80,6 +91,35 @@ class PropertyIoanVm extends _$PropertyIoanVm {
     return state;
   }
 
+  //刷新页面状态
+  void changeLoadingState(LoadState loadState, String? errorMsg) {
+    state = state.copyWith(
+        loadingState: loadState,
+        errorMessage: errorMsg
+    );
+  }
+
+  // 重试请求
+  Future retryRequest() async {
+    _needShowPlaceholder = true;
+    featchData();
+  }
+
+  // 初始化页面数据
+  initPageData() {
+    Log.d("----property_news_vm-----initPageData");
+    featchData();
+  }
+
+
+  Future featchData() async {
+    await Future.delayed(const Duration(milliseconds: 1500));
+    //更新展示的状态
+    changeLoadingState(LoadState.State_Success, null);
+    // 最后赋值
+    _needShowPlaceholder = false;
+  }
+
   requestQuoteConfirmAction(){
     Log.d("点击了确定");
     DialogEngine.dismiss(tag: "requestQuote");

+ 1 - 1
packages/cpt_property/lib/modules/ioan/property_ioan_vm.g.dart

@@ -6,7 +6,7 @@ part of 'property_ioan_vm.dart';
 // RiverpodGenerator
 // **************************************************************************
 
-String _$propertyIoanVmHash() => r'42f901fbd503e5b5a45c96781200412291240a37';
+String _$propertyIoanVmHash() => r'5b9c77252ac662163649b28c4d9ddaa2c793c344';
 
 /// See also [PropertyIoanVm].
 @ProviderFor(PropertyIoanVm)

+ 2 - 2
packages/cpt_property/lib/modules/news/page/property_news_state.dart

@@ -11,7 +11,7 @@ class PropertyNewsState {
 
     int? curPage;
     int? pageSize = 10;
-    int? filterCount = 0;
+    int? filterCount = 1;
     List<Map<String, dynamic>> list;
 
     PropertyNewsState({
@@ -19,7 +19,7 @@ class PropertyNewsState {
         String? errorMessage,
         this.curPage = 1,
         this.pageSize = 10,
-        this.filterCount = 0,
+        this.filterCount = 1,
         required this.list,
     });
 

+ 8 - 2
packages/cpt_property/lib/modules/news/vm/property_news_vm.dart

@@ -146,9 +146,15 @@ class PropertyNewsVm extends _$PropertyNewsVm {
     } else {
       //加载更多
       final allList = state.list;
-      allList.addAll(listData);
+      if(allList.length >= state.filterCount! * state.pageSize!){
+        //更新展示的状态
+        changeLoadingState(LoadState.State_Success, null);
+        // refreshController.finishLoad(IndicatorResult.noMore);
+      }else {
+        allList.addAll(listData);
+        state = state.copyWith(list: allList);
+      }
       refreshController.finishLoad();
-      state = state.copyWith(list: allList);
     }
 
     // 最后赋值

+ 1 - 1
packages/cpt_property/lib/modules/news/vm/property_news_vm.g.dart

@@ -6,7 +6,7 @@ part of 'property_news_vm.dart';
 // RiverpodGenerator
 // **************************************************************************
 
-String _$propertyNewsVmHash() => r'3a62be346ba45f73d4c4272c6b42cae5bfdfcdae';
+String _$propertyNewsVmHash() => r'81b5062b3ed866c4747a88c2e45a138fa9f5b1ef';
 
 /// See also [PropertyNewsVm].
 @ProviderFor(PropertyNewsVm)

+ 1 - 1
packages/cpt_property/lib/modules/rent/vm/property_rent_vm.g.dart

@@ -6,7 +6,7 @@ part of 'property_rent_vm.dart';
 // RiverpodGenerator
 // **************************************************************************
 
-String _$propertyRentVmHash() => r'2efb6c1e46d069748a306631c5265d2bc62599c7';
+String _$propertyRentVmHash() => r'5ba5583143e18939b38d3e8e843f65b8cbd90328';
 
 /// See also [PropertyRentVm].
 @ProviderFor(PropertyRentVm)

+ 1 - 1
packages/cpt_property/lib/modules/sale/vm/property_sale_vm.g.dart

@@ -6,7 +6,7 @@ part of 'property_sale_vm.dart';
 // RiverpodGenerator
 // **************************************************************************
 
-String _$propertySaleVmHash() => r'f24b1a7b9cbe075d7ed60302ab0c1d170359729b';
+String _$propertySaleVmHash() => r'54b18e906a735fe1089fed70b3b31ad58cd84037';
 
 /// See also [PropertySaleVm].
 @ProviderFor(PropertySaleVm)