Parcourir la source

1.钱包 - 修复登录后数据无刷新问题

2.热榜 - 加入缓存读取逻辑
tags/0.0.2+11^0
杨华轩 il y a 4 ans
Parent
révision
5fbdeae842
6 fichiers modifiés avec 167 ajouts et 42 suppressions
  1. +32
    -8
      lib/pages/wallet_page/wallet_page.dart
  2. +1
    -1
      lib/pages/wallet_page/wallet_page_bloc.dart
  3. +7
    -3
      lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart
  4. +18
    -3
      lib/widgets/wallet/wallet_data/wallet_data.dart
  5. +106
    -26
      lib/widgets/wallet/wallet_detail/wallet_detail.dart
  6. +3
    -1
      lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart

+ 32
- 8
lib/pages/wallet_page/wallet_page.dart Voir le fichier

@@ -5,6 +5,7 @@ import 'package:pull_to_refresh/pull_to_refresh.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_notifier.dart';
import 'package:zhiying_base_widget/utils/contants.dart';
import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_model.dart';
import 'package:zhiying_base_widget/widgets/refresh/refresh_header/refresh_header.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_appbar/wallet_appbar_sk.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
@@ -13,6 +14,7 @@ import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income_s
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'dart:ui';
import 'package:provider/provider.dart';

import 'wallet_page_bloc.dart';

@@ -33,12 +35,13 @@ class _WalletPageState extends State<WalletPage> {
backgroundColor: Color(0xfff9f9f9),
body: MultiProvider(
providers: [
ChangeNotifierProvider.value(value: MainPageNotifier()),
ChangeNotifierProvider.value(value: MainPageBgNotifier()),
ChangeNotifierProvider.value(value: BaseChangeNotifier()),
],
child: BlocProvider<WalletPageBloc>(
bloc: WalletPageBloc(),
child: _WalletPageContainer(data: widget.data),
child: _WalletPageContainer(
data: widget.data,
),
),
),
);
@@ -54,7 +57,8 @@ class _WalletPageContainer extends StatefulWidget {
_WalletPageContainerState createState() => _WalletPageContainerState();
}

class _WalletPageContainerState extends State<_WalletPageContainer> {
class _WalletPageContainerState extends State<_WalletPageContainer>
with AutomaticKeepAliveClientMixin {
ScrollController _controller;
RefreshController _refreshController;

@@ -71,9 +75,22 @@ class _WalletPageContainerState extends State<_WalletPageContainer> {
super.initState();
}

@override
void didChangeDependencies() {
var userInfo = Provider.of<UserInfoNotifier>(context);
if (userInfo != null) {
if (widget.data.containsKey(Constants.SkipIdentifierName)) {
_pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
Provider.of<BaseChangeNotifier>(context,listen: false).refresh();
}
}
super.didChangeDependencies();
}

@override
void dispose() {
_refreshController?.dispose();
Provider.of<BaseChangeNotifier>(context,listen: false).close();
super.dispose();
}

@@ -86,6 +103,7 @@ class _WalletPageContainerState extends State<_WalletPageContainer> {
void _onRefresh() async {
if (widget.data.containsKey(Constants.SkipIdentifierName)) {
_pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
Provider.of<BaseChangeNotifier>(context,listen: false).refresh();
}
}

@@ -93,7 +111,6 @@ class _WalletPageContainerState extends State<_WalletPageContainer> {
Widget build(BuildContext context) {
ScreenUtil.init(context, width: 750, height: 1334);
double top = MediaQueryData.fromWindow(window).padding.top;

return Container(
width: double.infinity,
child: Stack(
@@ -130,7 +147,8 @@ class _WalletPageContainerState extends State<_WalletPageContainer> {
);
}

List<Widget> _createContent(BuildContext context, List<Map<String, dynamic>> model) {
List<Widget> _createContent(
BuildContext context, List<Map<String, dynamic>> model) {
List<Widget> list = List();
if (model == null) {
///骨架图
@@ -148,12 +166,18 @@ class _WalletPageContainerState extends State<_WalletPageContainer> {
));
} else {
for (var item in model) {
WidgetModel widgetModel = WidgetModel.fromJson(Map<String, dynamic>.from(item));
list.addAll(WidgetFactory.create(widgetModel.modName, isSliver: true, model: item));
WidgetModel widgetModel =
WidgetModel.fromJson(Map<String, dynamic>.from(item));
list.addAll(WidgetFactory.create(widgetModel.modName,
isSliver: true, model: item));
}
}
return list;
}

@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}

// class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {


+ 1
- 1
lib/pages/wallet_page/wallet_page_bloc.dart Voir le fichier

@@ -11,7 +11,7 @@ import 'package:zhiying_comm/zhiying_comm.dart';
class WalletPageBloc extends BlocBase {

StreamController<List<Map<String, dynamic>>> _tabController =
StreamController<List<Map<String, dynamic>>>();
StreamController<List<Map<String, dynamic>>>.broadcast();

Stream<List<Map<String, dynamic>>> get outData => _tabController.stream;



+ 7
- 3
lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart Voir le fichier

@@ -30,16 +30,20 @@ class HotRankingListBloc extends BlocBase {
_dataController = null;
}

void loadData(String typeId, int page, Function complete) {
void loadData(String typeId, int page, Function complete) async {
if (isLoading) {
complete();
return;
}
isLoading = true;
currentTypeId = typeId;
NetUtil.request(
await NetUtil.request(
'/api/v1/rec/taobao?type_id=' + typeId + '&page=' + page.toString(),
method: NetMethod.GET, onSuccess: (data) {
method: NetMethod.GET, onCache: (data) {
complete();
Loading.dismiss();
_loadData(data);
}, onSuccess: (data) {
complete();
isLoading = false;
_loadData(data);


+ 18
- 3
lib/widgets/wallet/wallet_data/wallet_data.dart Voir le fichier

@@ -7,11 +7,12 @@ import 'package:zhiying_base_widget/widgets/wallet/wallet_data/model/wallet_head
import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_bloc.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:provider/provider.dart';

class WalletData extends StatefulWidget {
final Map<String, dynamic> data;

const WalletData(this.data, {Key key}) : super(key: key);
WalletData(this.data, {Key key}) : super(key: key);

@override
_WalletDataState createState() => _WalletDataState();
@@ -25,15 +26,29 @@ class _WalletDataState extends State<WalletData> {

@override
void initState() {
super.initState();
data = widget.data;
_bloc = WalletDataBloc();
_bloc.loadHeaderData();
super.initState();
}

@override
void didChangeDependencies() {

RefreshListener.listen(context, (event) {
_bloc.loadHeaderData();
});
super.didChangeDependencies();
}


@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
print(data);
WalletHeaderModel model;

return StreamBuilder(


+ 106
- 26
lib/widgets/wallet/wallet_detail/wallet_detail.dart Voir le fichier

@@ -9,6 +9,7 @@ import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_b
import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_sk.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:provider/provider.dart';

class WalletDetail extends StatefulWidget {
final Map<String, dynamic> data;
@@ -22,7 +23,8 @@ class WalletDetail extends StatefulWidget {
_WalletDetailState createState() => _WalletDetailState();
}

class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMixin {
class _WalletDetailState extends State<WalletDetail>
with TickerProviderStateMixin {
WalletDetailModel _model;

TabController _tabController;
@@ -33,13 +35,35 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
void initState() {
if (widget.data != null) {
_model = WalletDetailModel.fromJson(json.decode(widget.data['data']));
_tabController = TabController(length: _model.providers.length, vsync: this);
_tabController =
TabController(length: _model.providers.length, vsync: this);
}
_bloc = new WalletDetailBloc();
_bloc.loadData(_model.providers[0].type);

super.initState();
}


@override
void didChangeDependencies() {
RefreshListener.listen(context, (event) {
if (event == "refresh") {
if (_bloc.currentType == null) {
_bloc.loadData(_model.providers[0].type);
} else {
_bloc.loadData(_bloc.currentType);
}
}
});
super.didChangeDependencies();
}

@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
return StreamBuilder(
@@ -50,8 +74,10 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
return WalletDetailSkeleton();
}
return Container(
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 7.5, bottom: 7.5),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(8)),
margin:
EdgeInsets.only(left: 12.5, right: 12.5, top: 7.5, bottom: 7.5),
padding: const EdgeInsets.only(bottom: 13),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -70,10 +96,13 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
color: HexColor.fromHex(_model.providers[0].selectColor),
),
isScrollable: true,
unselectedLabelColor: HexColor.fromHex(_model.providers[0].unselectColor),
labelColor: HexColor.fromHex(_model.providers[0].selectColor),
unselectedLabelColor:
HexColor.fromHex(_model.providers[0].unselectColor),
labelColor:
HexColor.fromHex(_model.providers[0].selectColor),
controller: _tabController,
indicatorColor: HexColor.fromHex(_model.providers[0].selectColor),
indicatorColor:
HexColor.fromHex(_model.providers[0].selectColor),
indicatorSize: TabBarIndicatorSize.label,
onTap: (index) {
///变更平台
@@ -87,7 +116,7 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
height: 50,
alignment: Alignment.center,
child: ListView.builder(
padding: EdgeInsets.only( left: 8),
padding: EdgeInsets.only(left: 8),
itemCount: _model.dateList.length,
scrollDirection: Axis.horizontal,
itemBuilder: _buildTimeItem,
@@ -99,7 +128,11 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
height: 63,
margin: EdgeInsets.only(top: 16, left: 15, right: 15),
width: double.infinity,
decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(_model.providerDashbord.finish.bgImg), fit: BoxFit.fill)),
decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(
_model.providerDashbord.finish.bgImg),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@@ -109,7 +142,10 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
padding: const EdgeInsets.all(8.0),
child: Text(
_model.providerDashbord.finish.text,
style: TextStyle(fontSize: 14, color: HexColor.fromHex(_model.providerDashbord.finish.textColor)),
style: TextStyle(
fontSize: 14,
color: HexColor.fromHex(_model
.providerDashbord.finish.textColor)),
),
),
Row(
@@ -123,7 +159,9 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
child: Padding(
padding: const EdgeInsets.all(8.0),
child: CachedNetworkImage(
imageUrl: _model.providerDashbord.finish.tipIcon ?? "",
imageUrl:
_model.providerDashbord.finish.tipIcon ??
"",
width: 10,
height: 10,
fit: BoxFit.fill,
@@ -131,13 +169,19 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
),
onTap: () {
///显示弹窗
showTipDialog(null, _model.providerDashbord.finish.tipText);
showTipDialog(
null, _model.providerDashbord.finish.tipText);
})
],
),
Text(
_bloc.selectDateData.finish ?? "",
style: TextStyle(color: Colors.red, fontSize: 20, fontFamily: 'Din', package: 'zhiying_base_widget', fontWeight: FontWeight.bold),
style: TextStyle(
color: Colors.red,
fontSize: 20,
fontFamily: 'Din',
package: 'zhiying_base_widget',
fontWeight: FontWeight.bold),
)
],
),
@@ -149,7 +193,8 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return _buildBottomItem(context, index, _model.providerDashbord);
return _buildBottomItem(
context, index, _model.providerDashbord);
}),
)
],
@@ -165,7 +210,9 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
for (var item in _model.providers) {
listWidget.add(Text(
item.name,
style: TextStyle(fontSize: 14, ),
style: TextStyle(
fontSize: 14,
),
));
}
return listWidget;
@@ -177,14 +224,23 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
child: Container(
margin: EdgeInsets.only(top: 0, left: 8, right: 8),
decoration: BoxDecoration(
image: DecorationImage(image: CachedNetworkImageProvider(item.type == _bloc.selectDateData.type ? item.btnImg ?? "" : item.btnNoColorImg ?? ""), fit: BoxFit.fitWidth),
image: DecorationImage(
image: CachedNetworkImageProvider(
item.type == _bloc.selectDateData.type
? item.btnImg ?? ""
: item.btnNoColorImg ?? ""),
fit: BoxFit.fitWidth),
),
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 16),
child: Center(
child: Text(
item.text,
style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.type == _bloc.selectDateData.type ? item.textSelectColor : item.textUnselectColor)),
style: TextStyle(
fontSize: 11,
color: HexColor.fromHex(item.type == _bloc.selectDateData.type
? item.textSelectColor
: item.textUnselectColor)),
)),
),
),
@@ -201,7 +257,8 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
}

///底部显示
Widget _buildBottomItem(BuildContext context, int index, ProviderDashbord dashbord) {
Widget _buildBottomItem(
BuildContext context, int index, ProviderDashbord dashbord) {
SelfBuy item;
if (index == 0) {
item = dashbord.selfBuy;
@@ -223,7 +280,8 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
? Container()
: Text(
item.title,
style: TextStyle(color: HexColor.fromHex(item.titleColor), fontSize: 14),
style: TextStyle(
color: HexColor.fromHex(item.titleColor), fontSize: 14),
),
SizedBox(
height: 7.5,
@@ -236,7 +294,11 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
height: 61.5,
margin: EdgeInsets.only(right: 8, left: 15),
padding: EdgeInsets.only(left: 10),
decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[0].bgImg ?? ""), fit: BoxFit.fill)),
decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(
item.itemList[0].bgImg ?? ""),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -245,7 +307,10 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
children: <Widget>[
Text(
item.itemList[0].text ?? "",
style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[0].textColor)),
style: TextStyle(
fontSize: 11,
color: HexColor.fromHex(
item.itemList[0].textColor)),
),
InkWell(
child: Padding(
@@ -270,7 +335,8 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
package: 'zhiying_base_widget',
fontWeight: FontWeight.bold,
fontSize: 17,
color: HexColor.fromHex(item.itemList[1].valueColor),
color:
HexColor.fromHex(item.itemList[1].valueColor),
))
],
)),
@@ -278,9 +344,16 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
Expanded(
child: Container(
height: 61.5,
margin: EdgeInsets.only(left: 8, right: 15,),
margin: EdgeInsets.only(
left: 8,
right: 15,
),
padding: EdgeInsets.only(left: 10),
decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[1].bgImg ?? ""), fit: BoxFit.fill)),
decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(
item.itemList[1].bgImg ?? ""),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -289,7 +362,10 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
children: <Widget>[
Text(
item.itemList[1].text ?? "",
style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[1].textColor)),
style: TextStyle(
fontSize: 11,
color:
HexColor.fromHex(item.itemList[1].textColor)),
),
InkWell(
child: Padding(
@@ -311,7 +387,11 @@ class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMix
Text(
dataMap[item.itemList[1].vauleKey],
style: TextStyle(
fontSize: 17, color: HexColor.fromHex(item.itemList[1].valueColor), fontFamily: 'Din', package: 'zhiying_base_widget', fontWeight: FontWeight.bold),
fontSize: 17,
color: HexColor.fromHex(item.itemList[1].valueColor),
fontFamily: 'Din',
package: 'zhiying_base_widget',
fontWeight: FontWeight.bold),
)
],
),


+ 3
- 1
lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart Voir le fichier

@@ -19,6 +19,8 @@ class WalletDetailBloc extends BlocBase {

List<WalletDetailDataModel> listDataModel = new List();

String currentType;

@override
void dispose() {
_dataController.close();
@@ -30,6 +32,7 @@ class WalletDetailBloc extends BlocBase {
///
loadData(String type) async {
await NetUtil.request("/api/v1/user/wallet/" + type, onSuccess: (data) {
currentType = type;
listDataModel.clear();
listDataModel.addAll(List.from(data).map((v) {
return WalletDetailDataModel.fromJson(v);
@@ -38,7 +41,6 @@ class WalletDetailBloc extends BlocBase {
});
}


///刷新页面
refresh() {
for (var item in listDataModel) {


Chargement…
Annuler
Enregistrer