From b5cb67157c664a7bccc06c0ad27c9ae3abdc41ce Mon Sep 17 00:00:00 2001
From: PH2 <1293456824@qq.com>
Date: Mon, 26 Oct 2020 18:17:22 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83?=
=?UTF-8?q?=E7=9A=84=E5=AE=8C=E5=96=84=EF=BC=8C=E8=BF=98=E7=BC=BA=E5=85=AC?=
=?UTF-8?q?=E5=85=B1=E8=B7=B3=E8=BD=AC=202=E3=80=81Android=20=E5=90=AF?=
=?UTF-8?q?=E5=8A=A8=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../android/app/src/main/AndroidManifest.xml | 7 +-
.../main/res/drawable/launch_background.xml | 2 +-
.../main/res/drawable/normal_background.xml | 5 +
.../app/src/main/res/values/styles.xml | 4 +
.../bloc/message_notice_bloc.dart | 38 +-
.../bloc/message_notice_repository.dart | 59 +-
.../bloc/message_notice_state.dart | 12 +-
.../message_notice_page.dart | 619 ++++++++++--------
.../message_notice_page_sk.dart | 58 ++
.../model/message_notice_data_model.dart | 121 ++++
.../model/message_notice_style_model.dart | 12 +
lib/register.dart | 2 +-
12 files changed, 648 insertions(+), 291 deletions(-)
create mode 100644 example/android/app/src/main/res/drawable/normal_background.xml
create mode 100644 lib/pages/message_notice_page/message_notice_page_sk.dart
create mode 100644 lib/pages/message_notice_page/model/message_notice_data_model.dart
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index 5c2c46e..b6bbd5d 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -39,12 +39,13 @@
-
+
-
+
-
diff --git a/example/android/app/src/main/res/drawable/normal_background.xml b/example/android/app/src/main/res/drawable/normal_background.xml
new file mode 100644
index 0000000..e9b6c76
--- /dev/null
+++ b/example/android/app/src/main/res/drawable/normal_background.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml
index 00fa441..33fc5ee 100644
--- a/example/android/app/src/main/res/values/styles.xml
+++ b/example/android/app/src/main/res/values/styles.xml
@@ -5,4 +5,8 @@
Flutter draws its first frame -->
- @drawable/launch_background
+
+
diff --git a/lib/pages/message_notice_page/bloc/message_notice_bloc.dart b/lib/pages/message_notice_page/bloc/message_notice_bloc.dart
index c25a87f..48de94f 100644
--- a/lib/pages/message_notice_page/bloc/message_notice_bloc.dart
+++ b/lib/pages/message_notice_page/bloc/message_notice_bloc.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:zhiying_base_widget/pages/message_notice_page/bloc/message_notice_repository.dart';
+import 'package:zhiying_base_widget/pages/message_notice_page/model/message_notice_data_model.dart';
import 'package:zhiying_base_widget/pages/message_notice_page/model/message_notice_style_model.dart';
import 'package:zhiying_comm/util/empty_util.dart';
import 'package:zhiying_comm/util/log/let_log.dart';
@@ -44,20 +45,43 @@ class MessageNoticeBloc extends Bloc {
/// 初始化
Stream _mapInitEventToState(MessageNoticeInitEvent event) async* {
var cacheStyle = await repository.fetchCachedStyle();
- if(!EmptyUtil.isEmpty(cacheStyle)){
- yield MessageNoticeLoadedState(cacheStyle);
+ if (!EmptyUtil.isEmpty(cacheStyle)) {
+ // yield MessageNoticeLoadedState(styleModel: cacheStyle);
}
var netStyle = await repository.fetchNetStyle();
- if(!EmptyUtil.isEmpty(netStyle)){
- yield MessageNoticeLoadedState(netStyle);
+ if (!EmptyUtil.isEmpty(netStyle)) {
+ // yield MessageNoticeLoadedState(styleModel: netStyle);
Logger.log(netStyle.toJson().toString());
}
-
+ var data = await repository.fetchInitData();
+ if (!EmptyUtil.isEmpty(data) && (!EmptyUtil.isEmpty(netStyle) || !EmptyUtil.isEmpty(cacheStyle))) {
+ yield MessageNoticeLoadedState(dataModel: data, styleModel: !EmptyUtil.isEmpty(netStyle) ? netStyle : cacheStyle);
+ } else {
+ yield MessageNoticeInitErrorState();
+ }
}
/// 下拉刷新
- Stream _mapOnRefreshEventToState(MessageNoticeOnRefreshEvent event) async* {}
+ Stream _mapOnRefreshEventToState(MessageNoticeOnRefreshEvent event) async* {
+ var style = repository.getStyleModel();
+ var data = await repository.fetchRefreshData();
+ if (!EmptyUtil.isEmpty(data)) {
+ yield MessageNoticeOnRefreshSuccessState();
+ yield MessageNoticeLoadedState(styleModel: style, dataModel: data);
+ } else {
+ yield MessageNoticeOnRefreshErrorState();
+ }
+ }
/// 上拉更多
- Stream _mapOnLoadEventToState(MessageNoticeOnLoadEvent event) async* {}
+ Stream _mapOnLoadEventToState(MessageNoticeOnLoadEvent event) async* {
+ var style = repository.getStyleModel();
+ var data = await repository.fetchLoadData();
+ if (!EmptyUtil.isEmpty(data)) {
+ yield MessageNoticeOnLoadSuccessState();
+ yield MessageNoticeLoadedState(styleModel: style, dataModel: data);
+ } else {
+ yield MessageNoticeOnLoadErrorState();
+ }
+ }
}
diff --git a/lib/pages/message_notice_page/bloc/message_notice_repository.dart b/lib/pages/message_notice_page/bloc/message_notice_repository.dart
index 05801b6..105f349 100644
--- a/lib/pages/message_notice_page/bloc/message_notice_repository.dart
+++ b/lib/pages/message_notice_page/bloc/message_notice_repository.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
+import 'package:zhiying_base_widget/pages/message_notice_page/model/message_notice_data_model.dart';
import 'package:zhiying_base_widget/pages/message_notice_page/model/message_notice_style_model.dart';
import 'package:zhiying_comm/util/empty_util.dart';
import 'package:zhiying_comm/util/global_config.dart';
@@ -7,11 +8,28 @@ import 'package:zhiying_comm/util/log/let_log.dart';
import 'package:zhiying_comm/util/net_util.dart';
class MessageNoticeRepository {
+ String _type;
+ String _title;
+
final int _maxSize = 5;
int _currentPage = 1;
bool _hasMoreData = true;
MessageNoticeStyleModel _styleModel;
- List _oldData = [];
+ List _oldData = [];
+
+ MessageNoticeRepository(final Map data) {
+ try {
+ _type = !EmptyUtil.isEmpty(data) ? data.containsKey('type') ? data['type'] : 'main' : 'main';
+ _title = !EmptyUtil.isEmpty(data) ? data.containsKey('title') ? data['title'] : '消息中心' : '消息中心';
+ } catch (e, s) {
+ _type = 'main';
+ }
+ }
+
+ /// 获取样式数据
+ MessageNoticeStyleModel getStyleModel() {
+ return _styleModel;
+ }
/// 样式初始化(获取网络)
Future fetchNetStyle() async {
@@ -21,6 +39,13 @@ class MessageNoticeRepository {
var modListData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][0]['data'];
if (!EmptyUtil.isEmpty(modListData)) {
_styleModel = MessageNoticeStyleModel.fromJson(jsonDecode(modListData.toString()));
+ if (_type == 'main') {
+ _styleModel.isFist = true;
+ } else {
+ _styleModel.isFist = false;
+ }
+ _styleModel.styleType = _type;
+ _styleModel.styleTitle = _title ?? _styleModel.app_bar_name;
return _styleModel;
}
}
@@ -38,6 +63,13 @@ class MessageNoticeRepository {
var modListData = result['mod_list'][0]['data'];
if (!EmptyUtil.isEmpty(modListData)) {
_styleModel = MessageNoticeStyleModel.fromJson(jsonDecode(modListData.toString()));
+ if (_type == 'main') {
+ _styleModel.isFist = true;
+ } else {
+ _styleModel.isFist = false;
+ }
+ _styleModel.styleType = _type;
+ _styleModel.styleTitle = _title ?? _styleModel.app_bar_name;
return _styleModel;
}
}
@@ -48,12 +80,12 @@ class MessageNoticeRepository {
}
/// 下拉刷新
- Future fetchRefreshData() async {
+ Future fetchRefreshData() async {
return fetchInitData();
}
/// 上拉更多
- Future fetchLoadData() async {
+ Future fetchLoadData() async {
if (_hasMoreData) {
return _baseRequest();
}
@@ -61,7 +93,7 @@ class MessageNoticeRepository {
}
/// 数据初始化
- Future fetchInitData() async {
+ Future fetchInitData() async {
_currentPage = 1;
_hasMoreData = true;
_oldData.clear();
@@ -69,8 +101,23 @@ class MessageNoticeRepository {
}
/// 基础请求
- Future _baseRequest() async {
- try {} catch (e, s) {
+ Future _baseRequest() async {
+ try {
+ var result = await NetUtil.post('/api/v1/user/notice/$_type?page=${_currentPage.toString()}', method: NetMethod.GET);
+ if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
+ MessageNoticeDataModel dataModel = MessageNoticeDataModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
+ if (!EmptyUtil.isEmpty(dataModel) && !EmptyUtil.isEmpty(dataModel.list)) {
+ // if (dataModel.list.length >= _maxSize) {
+ ++_currentPage;
+ _hasMoreData = true;
+ dataModel.list.insertAll(0, _oldData);
+ // }
+ _oldData.addAll(dataModel.list);
+ return dataModel;
+ }
+ }
+ _hasMoreData = false;
+ } catch (e, s) {
Logger.error(e, s);
}
return null;
diff --git a/lib/pages/message_notice_page/bloc/message_notice_state.dart b/lib/pages/message_notice_page/bloc/message_notice_state.dart
index 4d1c23c..2d89f55 100644
--- a/lib/pages/message_notice_page/bloc/message_notice_state.dart
+++ b/lib/pages/message_notice_page/bloc/message_notice_state.dart
@@ -1,10 +1,10 @@
part of 'message_notice_bloc.dart';
-abstract class MessageNoticeState extends Equatable {
+abstract class MessageNoticeState {
const MessageNoticeState();
- @override
- List