123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import 'package:cpt_main/modules/notification/notification_group_data.dart';
- import 'package:plugin_platform/engine/toast/toast_engine.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:widgets/load_state_layout.dart';
- import 'package:widgets/widget_export.dart';
- import 'notification_state.dart';
- part 'notification_view_model.g.dart';
- @riverpod
- class NotificationViewModel extends _$NotificationViewModel {
- @override
- NotificationState build() {
- return NotificationState(datas: []);
- }
- var _curPage = 1;
- var _needShowPlaceholder = true;
-
- final EasyRefreshController refreshController = EasyRefreshController(
- controlFinishRefresh: true,
- controlFinishLoad: true,
- );
-
- void changeLoadingState(LoadState loadState, String? errorMsg) {
- state = state.copyWith(loadingState: loadState, errorMessage: errorMsg);
- }
-
- Future onRefresh() async {
- _curPage = 1;
- fetchList();
- }
-
- Future loadMore() async {
- _curPage++;
- fetchList();
- }
-
- Future retryRequest() async {
- _curPage = 1;
- _needShowPlaceholder = true;
- fetchList();
- }
-
- Future fetchList() async {
- if (_needShowPlaceholder) {
- changeLoadingState(LoadState.State_Loading, null);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- await Future.delayed(const Duration(milliseconds: 1500));
- List<NotificationGroupData> list = [];
- if (_curPage > 1) {
-
- } else {
- list.add(NotificationGroupData()
- ..groupId = "Toady"
- ..groupDatas = ["1", "2", "3", "4"]);
- list.add(NotificationGroupData()
- ..groupId = "Friday 11 oct 2024"
- ..groupDatas = ["1", "2", "3"]);
- list.add(NotificationGroupData()
- ..groupId = "Thursday 10 oct 2024"
- ..groupDatas = ["1", "2"]);
- list.add(NotificationGroupData()
- ..groupId = "Wednesday 9 oct 2024"
- ..groupDatas = ["1"]);
- }
- if (_curPage == 1) {
-
- state = state.copyWith(datas: list);
- refreshController.finishRefresh();
-
- changeLoadingState(LoadState.State_Success, null);
- } else {
-
- final allList = state.datas;
- allList.addAll(list);
- state.datas.addAll(list);
-
- refreshController.finishLoad(IndicatorResult.noMore);
- state = state.copyWith(datas: allList);
- }
-
- _needShowPlaceholder = false;
- }
-
- void markAll() {
- ToastEngine.show("点击标记全部");
- }
- }
|