@@ -61,8 +61,8 @@ class CustomItemPageBloc extends Bloc<CustomItemPageEvent, CustomItemPageState> | |||||
Stream<CustomItemPageState> _mapRefreshEventToState(CustomItemPageRefreshEvent event) async* { | Stream<CustomItemPageState> _mapRefreshEventToState(CustomItemPageRefreshEvent event) async* { | ||||
var netStyle = await repository.fetchNetStyle(); | var netStyle = await repository.fetchNetStyle(); | ||||
if (!EmptyUtil.isEmpty(netStyle)) { | if (!EmptyUtil.isEmpty(netStyle)) { | ||||
yield CustomItemPageRefreshSuccessState(); | |||||
yield CustomItemPageLoadedState(model: netStyle); | yield CustomItemPageLoadedState(model: netStyle); | ||||
yield CustomItemPageRefreshSuccessState(); | |||||
} else { | } else { | ||||
yield CustomItemPageRefreshErrorState(); | yield CustomItemPageRefreshErrorState(); | ||||
yield CustomItemPageErrorState(); | yield CustomItemPageErrorState(); | ||||
@@ -28,6 +28,9 @@ class CustomItemPageLoadSuccessState extends CustomItemPageState {} | |||||
/// 上拉更多失败 | /// 上拉更多失败 | ||||
class CustomItemPageLoadErrorState extends CustomItemPageState {} | class CustomItemPageLoadErrorState extends CustomItemPageState {} | ||||
/// 没有更多数据的情况 | |||||
class CustomItemPageNoMoreDataState extends CustomItemPageState {} | |||||
/// 其他错误 | /// 其他错误 | ||||
class CustomItemPageErrorState extends CustomItemPageState {} | class CustomItemPageErrorState extends CustomItemPageState {} | ||||
@@ -89,10 +89,6 @@ class __CustomItemPageContainerState extends BasePageState<_CustomItemPageContai | |||||
/// 刷新 | /// 刷新 | ||||
void _refreshEvent() { | void _refreshEvent() { | ||||
BlocProvider.of<CustomItemPageBloc>(context).add(CustomItemPageRefreshEvent()); | BlocProvider.of<CustomItemPageBloc>(context).add(CustomItemPageRefreshEvent()); | ||||
///刷新页面 | |||||
refreshPage(); | |||||
} | } | ||||
/// 下拉更多 | /// 下拉更多 | ||||
@@ -129,22 +125,34 @@ class __CustomItemPageContainerState extends BasePageState<_CustomItemPageContai | |||||
return BlocConsumer<CustomItemPageBloc, CustomItemPageState>( | return BlocConsumer<CustomItemPageBloc, CustomItemPageState>( | ||||
listener: (context, state) {}, | listener: (context, state) {}, | ||||
buildWhen: (prev, current) { | buildWhen: (prev, current) { | ||||
/// 下拉刷新成功 | |||||
if (current is CustomItemPageRefreshSuccessState) { | if (current is CustomItemPageRefreshSuccessState) { | ||||
_refreshController?.refreshCompleted(resetFooterState: true); | _refreshController?.refreshCompleted(resetFooterState: true); | ||||
///刷新页面 | |||||
refreshPage(); | |||||
return false; | return false; | ||||
} | } | ||||
/// 下拉刷新出错 | |||||
if (current is CustomItemPageRefreshErrorState) { | if (current is CustomItemPageRefreshErrorState) { | ||||
_refreshController?.refreshFailed(); | _refreshController?.refreshFailed(); | ||||
return false; | return false; | ||||
} | } | ||||
/// 上拉加载数据成功 | |||||
if (current is CustomItemPageLoadSuccessState) { | if (current is CustomItemPageLoadSuccessState) { | ||||
_refreshController?.loadComplete(); | _refreshController?.loadComplete(); | ||||
return false; | return false; | ||||
} | } | ||||
/// 上拉加载数据出错 | |||||
if (current is CustomItemPageLoadErrorState) { | if (current is CustomItemPageLoadErrorState) { | ||||
_refreshController?.loadNoData(); | _refreshController?.loadNoData(); | ||||
return false; | return false; | ||||
} | } | ||||
/// 上拉加载没有更多数据 | |||||
if (current is CustomItemPageNoMoreDataState) { | |||||
_refreshController?.loadNoData(); | |||||
return false; | |||||
} | |||||
/// 数据加载出错 | |||||
if (current is CustomItemPageErrorState) { | if (current is CustomItemPageErrorState) { | ||||
return false; | return false; | ||||
} | } | ||||
@@ -4,6 +4,7 @@ import 'dart:math'; | |||||
import 'package:bloc/bloc.dart'; | import 'package:bloc/bloc.dart'; | ||||
import 'package:flutter/cupertino.dart'; | import 'package:flutter/cupertino.dart'; | ||||
import 'package:zhiying_comm/util/empty_util.dart'; | import 'package:zhiying_comm/util/empty_util.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | |||||
import './bloc.dart'; | import './bloc.dart'; | ||||
@@ -25,8 +26,9 @@ class CustomQuickEntryBloc extends Bloc<CustomQuickEntryEvent, CustomQuickEntryS | |||||
/// 初始化 | /// 初始化 | ||||
Stream<CustomQuickEntryState> _mapHomeQuickEntryInitToState(CustomQuickEntryInitEvent event) async* { | Stream<CustomQuickEntryState> _mapHomeQuickEntryInitToState(CustomQuickEntryInitEvent event) async* { | ||||
/// 获取父页面传进来的数据 | /// 获取父页面传进来的数据 | ||||
var parentData = await repository.fetchPreantData(event: event); | |||||
var parentData = repository.fetchParentData(model: event?.model); | |||||
if (!EmptyUtil.isEmpty(parentData)) { | if (!EmptyUtil.isEmpty(parentData)) { | ||||
Logger.log('多言导航 == ' + parentData?.toJson()?.toString()); | |||||
yield CustomQuickEntryLoadedState(model: parentData); | yield CustomQuickEntryLoadedState(model: parentData); | ||||
} else { | } else { | ||||
yield CustomQuickEntryErrorState(); | yield CustomQuickEntryErrorState(); | ||||
@@ -1,10 +1,5 @@ | |||||
import 'package:equatable/equatable.dart'; | |||||
abstract class CustomQuickEntryEvent extends Equatable { | |||||
abstract class CustomQuickEntryEvent { | |||||
const CustomQuickEntryEvent(); | const CustomQuickEntryEvent(); | ||||
@override | |||||
List<Object> get props => []; | |||||
} | } | ||||
/// 初始事件 | /// 初始事件 | ||||
@@ -12,7 +7,4 @@ class CustomQuickEntryInitEvent extends CustomQuickEntryEvent { | |||||
final Map<String, dynamic> model; | final Map<String, dynamic> model; | ||||
const CustomQuickEntryInitEvent({this.model}); | const CustomQuickEntryInitEvent({this.model}); | ||||
@override | |||||
List<Object> get props => [this.model]; | |||||
} | } |
@@ -10,11 +10,11 @@ import 'custom_quick_entry_event.dart'; | |||||
class CustomQuickEntryRepository { | class CustomQuickEntryRepository { | ||||
/// 获取数据 | /// 获取数据 | ||||
Future<CustomQuickEntryModel> fetchData({@required CustomQuickEntryInitEvent event}) async { | |||||
Future<CustomQuickEntryModel> fetchData({@required Map<String, dynamic> model}) async { | |||||
try { | try { | ||||
var result = await NetUtil.post('/api/v1/mod/${event.model['mod_id']}', | |||||
var result = await NetUtil.post('/api/v1/mod/${model['mod_id']}', | |||||
params: { | params: { | ||||
'ids': [event.model['mod_id']] | |||||
'ids': [model['mod_id']] | |||||
}, | }, | ||||
cache: true, | cache: true, | ||||
method: NetMethod.GET); | method: NetMethod.GET); | ||||
@@ -31,9 +31,9 @@ class CustomQuickEntryRepository { | |||||
} | } | ||||
/// 获取父页面传进来的数据 | /// 获取父页面传进来的数据 | ||||
Future<CustomQuickEntryModel> fetchPreantData({@required CustomQuickEntryInitEvent event}) async { | |||||
CustomQuickEntryModel fetchParentData({@required Map<String, dynamic> model}) { | |||||
try { | try { | ||||
String jsonStr = event.model['data']; | |||||
String jsonStr = model['data']; | |||||
return CustomQuickEntryModel.fromJson(json.decode(jsonStr)); | return CustomQuickEntryModel.fromJson(json.decode(jsonStr)); | ||||
} catch (e, s) { | } catch (e, s) { | ||||
Logger.error(e, s); | Logger.error(e, s); | ||||
@@ -42,10 +42,10 @@ class CustomQuickEntryRepository { | |||||
} | } | ||||
/// 获取缓存数据 | /// 获取缓存数据 | ||||
Future<CustomQuickEntryModel> fetchCachedData({@required CustomQuickEntryInitEvent event}) async { | |||||
Future<CustomQuickEntryModel> fetchCachedData({@required Map<String, dynamic> model}) async { | |||||
try { | try { | ||||
var result = await NetUtil.getRequestCachedData('/api/v1/mod/${event.model['mod_id']}', params: { | |||||
'ids': [event.model['mod_id']] | |||||
var result = await NetUtil.getRequestCachedData('/api/v1/mod/${model['mod_id']}', params: { | |||||
'ids': [model['mod_id']] | |||||
}); | }); | ||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
return _getHomeQuickEntryModel(result); | return _getHomeQuickEntryModel(result); | ||||
@@ -18,12 +18,13 @@ class InitialCustomQuickEntryState extends CustomQuickEntryState { | |||||
/// 加载数据完毕 | /// 加载数据完毕 | ||||
class CustomQuickEntryLoadedState extends CustomQuickEntryState { | class CustomQuickEntryLoadedState extends CustomQuickEntryState { | ||||
final CustomQuickEntryModel model; | |||||
const CustomQuickEntryLoadedState({@required this.model}); | |||||
CustomQuickEntryModel model; | |||||
CustomQuickEntryLoadedState({@required this.model}); | |||||
// @override | |||||
// List<Object> get props => [this.model]; | |||||
@override | @override | ||||
List<Object> get props => [this.model]; | |||||
bool operator == (Object other) => false; | |||||
} | } | ||||
/// 加载缓存数据 | /// 加载缓存数据 | ||||
@@ -2,7 +2,6 @@ import 'dart:async'; | |||||
import 'package:flutter/cupertino.dart'; | import 'package:flutter/cupertino.dart'; | ||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:flutter_bloc/flutter_bloc.dart'; | |||||
import 'package:flutter_swiper/flutter_swiper.dart'; | import 'package:flutter_swiper/flutter_swiper.dart'; | ||||
import 'package:zhiying_base_widget/widgets/base_state/base_state.dart'; | import 'package:zhiying_base_widget/widgets/base_state/base_state.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
@@ -11,83 +10,96 @@ import 'custom_quick_entry_sk.dart'; | |||||
import 'model/custom_quick_entry_model.dart'; | import 'model/custom_quick_entry_model.dart'; | ||||
import 'bloc/bloc.dart'; | import 'bloc/bloc.dart'; | ||||
class CustomQuickEntry extends StatelessWidget { | |||||
class CustomQuickEntry extends StatefulWidget { | |||||
final Map<String, dynamic> model; | final Map<String, dynamic> model; | ||||
const CustomQuickEntry(this.model); | |||||
const CustomQuickEntry(this.model, {Key key}) : super(key: key); | |||||
@override | |||||
_CustomQuickEntryState createState() => _CustomQuickEntryState(); | |||||
} | |||||
class _CustomQuickEntryState extends BaseWidgetState<CustomQuickEntry> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { | |||||
CustomQuickEntryModel model; | |||||
CustomQuickEntryRepository _repository; | |||||
@override | |||||
bool get wantKeepAlive => true; | |||||
@override | |||||
void refreshWidget(String value) { | |||||
setState(() { | |||||
Logger.log('多言导航 ===== ' + widget?.model?.toString()); | |||||
model = _repository.fetchParentData(model: widget?.model); | |||||
}); | |||||
} | |||||
@override | |||||
void initState() { | |||||
_repository = CustomQuickEntryRepository(); | |||||
model = _repository.fetchParentData(model: widget?.model); | |||||
super.initState(); | |||||
} | |||||
@override | |||||
void dispose() { | |||||
model = null; | |||||
_repository = null; | |||||
super.dispose(); | |||||
} | |||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return BlocProvider<CustomQuickEntryBloc>( | |||||
create: (_) { | |||||
return CustomQuickEntryBloc(repository: CustomQuickEntryRepository())..add(CustomQuickEntryInitEvent(model: model)); | |||||
}, | |||||
child: _CustomQuickEntryContainer(model), | |||||
); | |||||
/// 空视图 | |||||
if (EmptyUtil.isEmpty(model)) { | |||||
return CustomQuickEntrySkeleton(); | |||||
} | |||||
if (model.isShowCategory == "1") { // 有分类 | |||||
return CustomQuickCateEntry(model: model); | |||||
} else { // 无分类 | |||||
return CustomQuickNormalEntry(model: model); | |||||
} | |||||
} | } | ||||
} | |||||
class _CustomQuickEntryContainer extends StatefulWidget { | |||||
final Map<String, dynamic> model; | |||||
} | |||||
_CustomQuickEntryContainer(this.model, {Key key}) : super(key: key); | |||||
/// | |||||
/// 无分类多眼导航 | |||||
/// | |||||
class CustomQuickNormalEntry extends StatefulWidget { | |||||
CustomQuickEntryModel model; | |||||
CustomQuickNormalEntry({this.model}); | |||||
@override | @override | ||||
__CustomQuickEntryContainerState createState() => __CustomQuickEntryContainerState(); | |||||
_CustomQuickNormalEntryState createState() => _CustomQuickNormalEntryState(); | |||||
} | } | ||||
class __CustomQuickEntryContainerState extends BaseWidgetState<_CustomQuickEntryContainer> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { | |||||
class _CustomQuickNormalEntryState extends State<CustomQuickNormalEntry> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { | |||||
SwiperController _controller; | |||||
/// Icon点击事件 | /// Icon点击事件 | ||||
void _itemIconClick(ListStyle model) { | void _itemIconClick(ListStyle model) { | ||||
print("item type = ${model.skipIdentifier}"); | print("item type = ${model.skipIdentifier}"); | ||||
// Navigator.push(context, CupertinoPageRoute(builder: (_) => CommonPage(null))); | |||||
RouterUtil.route(model, model.toJson(), context); | RouterUtil.route(model, model.toJson(), context); | ||||
} | } | ||||
SwiperController _controller; | |||||
@override | @override | ||||
void initState() { | void initState() { | ||||
_controller = SwiperController(); | _controller = SwiperController(); | ||||
print(widget?.model); | |||||
super.initState(); | super.initState(); | ||||
} | } | ||||
@override | @override | ||||
void dispose() { | void dispose() { | ||||
_controller?.dispose(); | _controller?.dispose(); | ||||
super.dispose(); | super.dispose(); | ||||
} | } | ||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return BlocConsumer<CustomQuickEntryBloc, CustomQuickEntryState>( | |||||
listener: (context, state) {}, | |||||
buildWhen: (prev, current) { | |||||
if (prev is CustomQuickEntryLoadedState) { | |||||
return false; | |||||
} | |||||
return true; | |||||
}, | |||||
builder: (context, state) { | |||||
print("构建"); | |||||
if (state is CustomQuickEntryCachedState) { | |||||
return _getMainWidget(state.model); | |||||
} | |||||
if (state is CustomQuickEntryLoadedState) { | |||||
if (state.model.isShowCategory == "1") { | |||||
return CustomQuickCateEntry(model: state.model); | |||||
} else { | |||||
return _getMainWidget(state.model); | |||||
} | |||||
} | |||||
if (state is CustomQuickEntryErrorState) { | |||||
return Container(); | |||||
} | |||||
return CustomQuickEntrySkeleton(); | |||||
}, | |||||
); | |||||
return _getMainWidget(widget?.model); | |||||
} | } | ||||
Widget _getMainWidget(CustomQuickEntryModel model) { | Widget _getMainWidget(CustomQuickEntryModel model) { | ||||
@@ -261,15 +273,15 @@ class __CustomQuickEntryContainerState extends BaseWidgetState<_CustomQuickEntry | |||||
/// 行的数据 | /// 行的数据 | ||||
Widget _getRowWidget( | Widget _getRowWidget( | ||||
{double titleHeight, | {double titleHeight, | ||||
double iconHeight, | |||||
int totalPage, | |||||
int currentPage, | |||||
int columSize, | |||||
int totalRowSize, | |||||
int totalDataSize, | |||||
CustomQuickEntryModel model, | |||||
int currentRow, | |||||
double itemHeight}) { | |||||
double iconHeight, | |||||
int totalPage, | |||||
int currentPage, | |||||
int columSize, | |||||
int totalRowSize, | |||||
int totalDataSize, | |||||
CustomQuickEntryModel model, | |||||
int currentRow, | |||||
double itemHeight}) { | |||||
List itemList = []; | List itemList = []; | ||||
for (int i = 0; i < columSize; i++) { | for (int i = 0; i < columSize; i++) { | ||||
itemList.add(i); | itemList.add(i); | ||||
@@ -299,16 +311,16 @@ class __CustomQuickEntryContainerState extends BaseWidgetState<_CustomQuickEntry | |||||
/// item 的数据 | /// item 的数据 | ||||
Widget _getColumWidget( | Widget _getColumWidget( | ||||
{double titleHeight, | {double titleHeight, | ||||
double iconHeight, | |||||
int totalPage, | |||||
int currentPage, | |||||
int columSize, | |||||
int totalRowSize, | |||||
int totalDataSize, | |||||
CustomQuickEntryModel model, | |||||
int currentRow, | |||||
int currentColum, | |||||
double itemHeight}) { | |||||
double iconHeight, | |||||
int totalPage, | |||||
int currentPage, | |||||
int columSize, | |||||
int totalRowSize, | |||||
int totalDataSize, | |||||
CustomQuickEntryModel model, | |||||
int currentRow, | |||||
int currentColum, | |||||
double itemHeight}) { | |||||
// 当前index = 当前的页数+1 * 当前的行数 + 当前的列数 | // 当前index = 当前的页数+1 * 当前的行数 + 当前的列数 | ||||
// int currentIndex = (currentPage + 1) * currentRow + currentColum + currentRow*columSize; | // int currentIndex = (currentPage + 1) * currentRow + currentColum + currentRow*columSize; | ||||
// int currentIndex = currentPage != 0 ? currentPage * (columSize * totalRowSize) + columSize + currentRow * columSize : | // int currentIndex = currentPage != 0 ? currentPage * (columSize * totalRowSize) + columSize + currentRow * columSize : | ||||
@@ -447,33 +459,15 @@ class __CustomQuickEntryContainerState extends BaseWidgetState<_CustomQuickEntry | |||||
}); | }); | ||||
} | } | ||||
@override | |||||
// TODO: implement wantKeepAlive | |||||
bool get wantKeepAlive => true; | |||||
@override | @override | ||||
void refreshWidget(String value) { | |||||
setState(() {}); | |||||
} | |||||
bool get wantKeepAlive => true; | |||||
} | } | ||||
/// | /// | ||||
/// 图片build 优化 | |||||
/// 有分类多眼导航 | |||||
/// | /// | ||||
class MyNetWorkImage extends StatelessWidget { | |||||
final String imgUrl; | |||||
final double width; | |||||
const MyNetWorkImage(this.imgUrl, {this.width = 40}); | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return RepaintBoundary( | |||||
child: CachedNetworkImage(width: width, imageUrl: imgUrl), | |||||
); | |||||
} | |||||
} | |||||
class CustomQuickCateEntry extends StatefulWidget { | class CustomQuickCateEntry extends StatefulWidget { | ||||
final CustomQuickEntryModel model; | final CustomQuickEntryModel model; | ||||
@@ -483,7 +477,8 @@ class CustomQuickCateEntry extends StatefulWidget { | |||||
_CustomQuickCateEntryState createState() => _CustomQuickCateEntryState(); | _CustomQuickCateEntryState createState() => _CustomQuickCateEntryState(); | ||||
} | } | ||||
class _CustomQuickCateEntryState extends BaseWidgetState<CustomQuickCateEntry> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { | |||||
class _CustomQuickCateEntryState extends State<CustomQuickCateEntry> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { | |||||
TabController tabController; | TabController tabController; | ||||
bool isOnTap = false; | bool isOnTap = false; | ||||
@@ -980,11 +975,6 @@ class _CustomQuickCateEntryState extends BaseWidgetState<CustomQuickCateEntry> w | |||||
@override | @override | ||||
bool get wantKeepAlive => true; | bool get wantKeepAlive => true; | ||||
@override | |||||
void refreshWidget(String value) { | |||||
BlocProvider.of<CustomQuickEntryBloc>(context).add(CustomQuickEntryInitEvent(model: widget?.model?.toJson())); | |||||
} | |||||
} | } | ||||
class PageItem { | class PageItem { | ||||
@@ -994,3 +984,20 @@ class PageItem { | |||||
List<ListStyle> listStyle; | List<ListStyle> listStyle; | ||||
} | } | ||||
/// | |||||
/// 图片build 优化 | |||||
/// | |||||
class MyNetWorkImage extends StatelessWidget { | |||||
final String imgUrl; | |||||
final double width; | |||||
const MyNetWorkImage(this.imgUrl, {this.width = 40}); | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return RepaintBoundary( | |||||
child: CachedNetworkImage(width: width, imageUrl: imgUrl), | |||||
); | |||||
} | |||||
} |
@@ -21,7 +21,7 @@ class CustomNoticeBloc extends Bloc<CustomNoticeEvent, CustomNoticeState> { | |||||
/// 初始化 | /// 初始化 | ||||
Stream<CustomNoticeState> _mapInitEventToState(CustomNoticeInitEvent event) async* { | Stream<CustomNoticeState> _mapInitEventToState(CustomNoticeInitEvent event) async* { | ||||
var parentData = await repository.fetchParentData(event); | |||||
var parentData = repository.fetchParentData(event?.model); | |||||
if(!EmptyUtil.isEmpty(parentData)) | if(!EmptyUtil.isEmpty(parentData)) | ||||
yield CustomNoticeLoadedState(model: parentData); | yield CustomNoticeLoadedState(model: parentData); | ||||
else | else | ||||
@@ -4,9 +4,9 @@ import 'bloc.dart'; | |||||
class CustomNoticeRepository { | class CustomNoticeRepository { | ||||
/// 获取父页面的数据 | /// 获取父页面的数据 | ||||
Future<CustomNoticeModel> fetchParentData(CustomNoticeInitEvent event) async { | |||||
CustomNoticeModel fetchParentData(final Map<String, dynamic> model) { | |||||
try { | try { | ||||
String jsonStr = event.model['data']; | |||||
String jsonStr = model['data']; | |||||
return CustomNoticeModel.fromJson(jsonDecode(jsonStr)); | return CustomNoticeModel.fromJson(jsonDecode(jsonStr)); | ||||
} catch (e) { | } catch (e) { | ||||
Logger.log(e); | Logger.log(e); | ||||
@@ -6,32 +6,24 @@ import 'package:cached_network_image/cached_network_image.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
import 'bloc/bloc.dart'; | import 'bloc/bloc.dart'; | ||||
import 'custom_notice_sk.dart'; | import 'custom_notice_sk.dart'; | ||||
import 'package:zhiying_base_widget/widgets/base_state/base_state.dart'; | |||||
/// | /// | ||||
/// 公告滚动widget | /// 公告滚动widget | ||||
/// | /// | ||||
class CustomNoticeWidget extends StatelessWidget { | |||||
class CustomNoticeWidget extends StatefulWidget { | |||||
final Map<String, dynamic> model; | final Map<String, dynamic> model; | ||||
const CustomNoticeWidget(this.model); | const CustomNoticeWidget(this.model); | ||||
@override | @override | ||||
Widget build(BuildContext context) { | |||||
return BlocProvider<CustomNoticeBloc>( | |||||
create: (_) => | |||||
CustomNoticeBloc(repository: CustomNoticeRepository()) | |||||
..add(CustomNoticeInitEvent(model: model)), | |||||
child: _CustomNoticeWidgetContainer(), | |||||
); | |||||
} | |||||
_CustomNoticeWidgetState createState() => _CustomNoticeWidgetState(); | |||||
} | } | ||||
class _CustomNoticeWidgetContainer extends StatefulWidget { | |||||
@override | |||||
_CustomNoticeWidgetContainerState createState() => _CustomNoticeWidgetContainerState(); | |||||
} | |||||
class _CustomNoticeWidgetState extends BaseWidgetState<CustomNoticeWidget> { | |||||
CustomNoticeModel model; | |||||
CustomNoticeRepository _repository; | |||||
class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContainer> { | |||||
/// 子item点击事件 | /// 子item点击事件 | ||||
void _itemOnClick(CustomNoticeModel model) { | void _itemOnClick(CustomNoticeModel model) { | ||||
if (pageIndex == model.listStyle.length) { | if (pageIndex == model.listStyle.length) { | ||||
@@ -48,20 +40,33 @@ class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContain | |||||
RouterUtil.route(model, model.toJson(), context); | RouterUtil.route(model, model.toJson(), context); | ||||
} | } | ||||
@override | |||||
void refreshWidget(String value) { | |||||
setState(() { | |||||
model = _repository.fetchParentData(widget?.model); | |||||
}); | |||||
} | |||||
@override | |||||
void initState() { | |||||
_repository = new CustomNoticeRepository(); | |||||
model = _repository.fetchParentData(widget?.model); | |||||
super.initState(); | |||||
} | |||||
@override | |||||
void dispose() { | |||||
model = null; | |||||
_repository = null; | |||||
super.dispose(); | |||||
} | |||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return BlocConsumer<CustomNoticeBloc, CustomNoticeState>( | |||||
listener: (context, state) {}, | |||||
buildWhen: (prev, current) { | |||||
return true; | |||||
}, | |||||
builder: (context, state) { | |||||
if (state is CustomNoticeLoadedState) { | |||||
return _getMainWidget(state?.model); | |||||
} | |||||
return CustomNoticeSkeleton(); | |||||
}, | |||||
); | |||||
if (!EmptyUtil.isEmpty(model)) | |||||
return _getMainWidget(model); | |||||
else | |||||
return CustomNoticeSkeleton(); | |||||
} | } | ||||
/// 主体页面 | /// 主体页面 | ||||
@@ -138,8 +143,10 @@ class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContain | |||||
), | ), | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
// 上下滚动的消息轮播 | // 上下滚动的消息轮播 | ||||
class MarqueeWidget extends StatefulWidget { | class MarqueeWidget extends StatefulWidget { | ||||
int count; // 子视图数量 | int count; // 子视图数量 | ||||
@@ -26,7 +26,7 @@ class CustomSlideBannerBloc extends Bloc<CustomSlideBannerEvent, CustomSlideBann | |||||
/// 初始化 | /// 初始化 | ||||
Stream<CustomSlideBannerState> _mapInitEventToState(CustomBannerInitEvent event) async* { | Stream<CustomSlideBannerState> _mapInitEventToState(CustomBannerInitEvent event) async* { | ||||
var parent = await repository.fetchPreantData(event.model); | |||||
var parent = repository.fetchParentData(event.model); | |||||
if (!EmptyUtil.isEmpty(parent)) { | if (!EmptyUtil.isEmpty(parent)) { | ||||
yield HomeSlideBannerLoadedState(datas: parent); | yield HomeSlideBannerLoadedState(datas: parent); | ||||
return; | return; | ||||
@@ -19,7 +19,7 @@ class CustomSlideBannerRepository { | |||||
} | } | ||||
/// 获取父页面传进来的数据 | /// 获取父页面传进来的数据 | ||||
Future<CustomSlideBannerModel> fetchPreantData(@required Map<String, dynamic> model) async { | |||||
CustomSlideBannerModel fetchParentData(@required Map<String, dynamic> model) { | |||||
try { | try { | ||||
if (!EmptyUtil.isEmpty(model)) { | if (!EmptyUtil.isEmpty(model)) { | ||||
return CustomSlideBannerModel.fromJson(jsonDecode(model['data'])); | return CustomSlideBannerModel.fromJson(jsonDecode(model['data'])); | ||||
@@ -1,7 +1,6 @@ | |||||
import 'package:cached_network_image/cached_network_image.dart'; | import 'package:cached_network_image/cached_network_image.dart'; | ||||
import 'package:flutter/cupertino.dart'; | import 'package:flutter/cupertino.dart'; | ||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:flutter_bloc/flutter_bloc.dart'; | |||||
import 'package:flutter_swiper/flutter_swiper.dart'; | import 'package:flutter_swiper/flutter_swiper.dart'; | ||||
import 'package:provider/provider.dart'; | import 'package:provider/provider.dart'; | ||||
import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; | import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; | ||||
@@ -10,6 +9,7 @@ import 'bloc/bloc.dart'; | |||||
import 'bloc/custom_slide_banner_repository.dart'; | import 'bloc/custom_slide_banner_repository.dart'; | ||||
import 'custom_slide_banner_sk.dart'; | import 'custom_slide_banner_sk.dart'; | ||||
import 'model/custom_slide_banner_model.dart'; | import 'model/custom_slide_banner_model.dart'; | ||||
import 'package:zhiying_base_widget/widgets/base_state/base_state.dart'; | |||||
/// | /// | ||||
/// 可滑动 banner 轮播图 | /// 可滑动 banner 轮播图 | ||||
@@ -23,71 +23,48 @@ class CustomSlideBanner extends StatefulWidget { | |||||
_CustomSlideBannerState createState() => _CustomSlideBannerState(); | _CustomSlideBannerState createState() => _CustomSlideBannerState(); | ||||
} | } | ||||
class _CustomSlideBannerState extends State<CustomSlideBanner> { | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return BlocProvider<CustomSlideBannerBloc>( | |||||
create: (_) => CustomSlideBannerBloc(repository: CustomSlideBannerRepository())..add(CustomBannerInitEvent(model: widget?.model)), | |||||
child: CustomSlideBannerContainer(), | |||||
); | |||||
} | |||||
} | |||||
class _CustomSlideBannerState extends BaseWidgetState<CustomSlideBanner> { | |||||
class CustomSlideBannerContainer extends StatefulWidget { | |||||
@override | |||||
_CustomSlideBannerContainerState createState() => _CustomSlideBannerContainerState(); | |||||
} | |||||
CustomSlideBannerRepository _repository; | |||||
CustomSlideBannerModel model; | |||||
SwiperController _swiperController; | |||||
class _CustomSlideBannerContainerState extends State<CustomSlideBannerContainer> { | |||||
/// 子元素点击事件 | /// 子元素点击事件 | ||||
void _itemOnClick(IndexCarouselList model) { | void _itemOnClick(IndexCarouselList model) { | ||||
print('点击了 $model'); | print('点击了 $model'); | ||||
RouterUtil.route(model, model.toJson(), context); | RouterUtil.route(model, model.toJson(), context); | ||||
// Navigator.push(context, CupertinoPageRoute(builder: (_) => VipCenterPage(null))); | |||||
} | } | ||||
SwiperController _swiperController; | |||||
@override | @override | ||||
void initState() { | void initState() { | ||||
_swiperController = SwiperController(); | _swiperController = SwiperController(); | ||||
_repository = CustomSlideBannerRepository(); | |||||
model = _repository.fetchParentData(widget?.model); | |||||
super.initState(); | super.initState(); | ||||
} | } | ||||
@override | |||||
void refreshWidget(String value) { | |||||
setState(() { | |||||
model = _repository.fetchParentData(widget?.model); | |||||
}); | |||||
} | |||||
@override | @override | ||||
void dispose() { | void dispose() { | ||||
_swiperController.stopAutoplay(); | |||||
_swiperController?.stopAutoplay(); | |||||
_swiperController?.dispose(); | _swiperController?.dispose(); | ||||
_repository = null; | |||||
model = null; | |||||
super.dispose(); | super.dispose(); | ||||
} | } | ||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return BlocConsumer<CustomSlideBannerBloc, CustomSlideBannerState>( | |||||
listener: (BuildContext context, CustomSlideBannerState state) { | |||||
if (state is HomeSlideBannerLoadError) { | |||||
print('数据加载出错'); | |||||
} | |||||
}, | |||||
buildWhen: (previous, current) { | |||||
/// 数据加载出错不进行build | |||||
if (current is HomeSlideBannerLoadError) { | |||||
return false; | |||||
} | |||||
return true; | |||||
}, | |||||
builder: (context, state) { | |||||
print('currente state = $state'); | |||||
if (state is HomeSlideBannerLoadedState) { | |||||
return _getMainWidget(state.datas); | |||||
} | |||||
if (state is CustomSlideBannerCachedState) { | |||||
return _getMainWidget(state.datas); | |||||
} | |||||
// 骨架屏 | |||||
return CustomSlideBannerSkeleton(); | |||||
}, | |||||
); | |||||
if (!EmptyUtil.isEmpty(model)) | |||||
return _getMainWidget(model); | |||||
else | |||||
return CustomSlideBannerSkeleton(); | |||||
} | } | ||||
Widget _getMainWidget(CustomSlideBannerModel datas) { | Widget _getMainWidget(CustomSlideBannerModel datas) { | ||||
@@ -260,3 +237,4 @@ class _CustomSlideBannerContainerState extends State<CustomSlideBannerContainer> | |||||
margin: const EdgeInsets.only(), builder: DotSwiperPaginationBuilder(color: HexColor.fromHex(unselectColor), activeColor: HexColor.fromHex(selectColor), size: 8, activeSize: 8)); | margin: const EdgeInsets.only(), builder: DotSwiperPaginationBuilder(color: HexColor.fromHex(unselectColor), activeColor: HexColor.fromHex(selectColor), size: 8, activeSize: 8)); | ||||
} | } | ||||
} | } | ||||