我有一个页面连接到appstate和viewmodel,
我在此页面中执行的操作是从图库中拾取图像,然后将其发送到服务器,当我向用户发送提示消息时,他可以看到用户正在加载的图像, 当上载史诗结束时,将执行一个动作,然后执行化简操作,从而更改状态,以便页面中的ui发生更改,
reduce接收到它并返回一个状态,但是onDidChange不会在紧接之后提示,
这是一些代码:
页面构建方法:
@override
Widget build(BuildContext context) {
return new StoreConnector<AppState, AddRefundViewModel>(
converter: addRefundConverter,
onInitialBuild: (AddRefundViewModel vm) => {vm.doInitializeDto()},
builder: (context, vm) {
return MaterialApp(
title: 'Test',
home: Scaffold(
body: Column(
children: <Widget>[
Container(
child: new Column(
children: <Widget>[
RefundHeader1(context, vm),
RefundHeader(context, vm),
],
),
decoration: new BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerRight,
end: Alignment.bottomLeft,
colors: [primary, primaryGradient]),
),
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.width * 0.4,
),
//Text(vm.c),
refundRowSum(vm),
refundRowDate(context, vm),
refundRowCurrent(context, vm),
refundRowRefund(context, vm),
refundRowAtm(context, vm),
Expanded(child: Container(
child: GestureDetector(onTap: () {
//print("tap");}
// myFocusNode.dispose();},
if (myFocusNode != null) {
FocusScope.of(context).requestFocus(new FocusNode());
}
}),
)),
proceedMessage(context, vm),
],
),
bottomNavigationBar: BottomAppBar(
child: proceedButton(context, vm),
),
resizeToAvoidBottomPadding: false,
));
},
onDidChange: (vm) {
print('---!!!!-----<<<<<<<<<<<<<< onDidChange >>>>>>>>>>>-----!!!------');
if (vm.addRefundDto.tmpFileStat == TmpFileStat.BadExt) {
showSendReceiptDialog2(context, TmpFileStat.BadExt);
vm.doInitTmpFileStat();
} else if (vm.addRefundDto.tmpFileStat == TmpFileStat.TooLarge) {
showSendReceiptDialog2(context, TmpFileStat.TooLarge);
vm.doInitTmpFileStat();
}
else if (vm.addRefundDto.uploadRefundStatus ==
RefundUpload.Success ||vm.addRefundDto.uploadRefundStatus ==
RefundUpload.Started ||
vm.addRefundDto.uploadRefundStatus == RefundUpload.Failed) {
Navigator.pop(context);
showSendReceiptDialog(context, vm.addRefundDto.uploadRefundStatus);
}
},
);}
减速器:
case GotRefund:
print('----=== GotRefund add new refund reducer ===-----');
AddRefundDto refundDto = state.refundDto;
refundDto.uploadRefundStatus=RefundUpload.Success;
state.refundDto= refundDto;
return new AddRefundState(
fileDto: null,
byteImage: null,
refundDto: state.refundDto,
);
添加的ViewModel:
import 'package:flutter/widgets.dart';
import 'package:iai/models/add_refund_dto.dart';
import 'package:iai/store/ui/ui_state.dart';
import 'package:iai/theme/images.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:iai/models/currency.dart';
class AddRefundViewModel {
bool fileAttachment;
DateTime pickedDate;
double amount;
bool isAtm;
bool canProceed;
AddRefundDto addRefundDto;
//final List<String> refundList;
final Map<String, AssetImage> refundList;
final Map<String, IconData> currencyList;
final List<Currency> currencyList2;
Function saveCurrentViewModel;
Function sendDtoToServer;
Function openGallery;
Function openCamera;
Function doInitializeDto;
Function doRemoveTmpImage;
Function doInitTmpFileStat;
final Function search;
final String searchTerm;
final bool showSearch;
AddRefundViewModel({
this.openCamera,
this.openGallery,
this.addRefundDto,
this.search,
this.searchTerm,
this.showSearch,
this.doInitializeDto,
this.doRemoveTmpImage,
this.doInitTmpFileStat,
this.refundList,
this.sendDtoToServer,
this.saveCurrentViewModel,
this.pickedDate,
this.amount,
this.currencyList,
this.isAtm,
this.canProceed,
this.currencyList2,
this.fileAttachment,
});
}
感谢所有能做出贡献的人
答案 0 :(得分:1)
您还可以在这里发布您的AddRefundViewModel类吗?我认为onDidChange是基于这些变量调用的。