123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import 'package:plugin_platform/http/http_result.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:shared/utils/log_utils.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_rent_state.dart';
- import '../repository/property_rent_repository.dart';
- part 'property_rent_vm.g.dart';
- @riverpod
- class PropertyRentVm extends _$PropertyRentVm {
- late PropertyRentRepository propertyRentRepository;
- bool _needShowPlaceholder = true;
-
- final EasyRefreshController refreshController = EasyRefreshController(
- controlFinishRefresh: true,
- controlFinishLoad: true,
- );
- PropertyRentState initState() {
- return PropertyRentState(
- list: [],
- );
- }
- @override
- PropertyRentState build() {
-
- propertyRentRepository = ref.read(propertyRentRepositoryProvider);
-
- PropertyRentState state = initState();
-
- return state;
- }
-
- void changeLoadingState(LoadState loadState, String? errorMsg) {
- state = state.copyWith(
- loadingState: loadState,
- errorMessage: errorMsg
- );
- }
-
- initPageData() {
- Log.d("----property_news_vm-----initPageData");
- onRefresh();
- }
-
- Future loadMore() async {
- Log.d("----property_news_vm-----loadMore");
-
-
-
-
-
-
-
-
-
- int newCurPage = state.curPage ?? 1;
- state = state.copyWith(curPage: ++newCurPage);
- getListData();
- }
-
- Future onRefresh() async {
- Log.d("----property_news_vm-----onRefresh ");
-
- state = state.copyWith(curPage: 1);
- getListData();
- }
-
- Future retryRequest() async {
- state = state.copyWith(curPage: 1);
- _needShowPlaceholder = true;
- getListData();
- }
-
- Future getListData<T>() async {
- if (_needShowPlaceholder) {
- changeLoadingState(LoadState.State_Loading, null);
- }
- Log.d("加载listData数据---------------start--${state.curPage}---");
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- await Future.delayed(const Duration(milliseconds: 1500));
- final List<Map<String, dynamic>> listData = [
- {
- "id": 1,
- "title": "Jul 2024 Blk XX #XX to XX 1,100 - 1,200 sqft",
- "price": "\$4000",
- "unit": "per month",
- },
- {
- "id": 2,
- "title": "Jul 2024 Blk XX #XX to XX 1,100 - 1,200 sqft",
- "price": "\$4000",
- "unit": "per month",
- },
- ];
- 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;
- }
- }
|