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