price dot fix

4.4
Serik Uvaissov 2020-07-02 15:50:34 +06:00
parent 72df9c777c
commit 2826d56a73
2 changed files with 114 additions and 57 deletions

View File

@ -51,7 +51,7 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
), ),
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), padding: const EdgeInsets.only(top: 15, left: 10, right: 15),
child: ListView( child: ListView(
controller: widget.scrollController, controller: widget.scrollController,
children: <Widget>[ children: <Widget>[
@ -74,7 +74,9 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
labelText: 'Количество', labelText: 'Количество',
prefixText: ' ', prefixText: ' ',
), ),
keyboardType: const TextInputType.numberWithOptions(decimal: false,), keyboardType: const TextInputType.numberWithOptions(
decimal: false,
),
inputFormatters: <TextInputFormatter>[ inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly WhitelistingTextInputFormatter.digitsOnly
], ],
@ -90,7 +92,8 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
labelText: 'Стоимость', labelText: 'Стоимость',
prefixText: ' ', prefixText: ' ',
), ),
keyboardType: const TextInputType.numberWithOptions(decimal: true), keyboardType:
const TextInputType.numberWithOptions(decimal: true),
inputFormatters: <TextInputFormatter>[ inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp("^[0-9.]*")), WhitelistingTextInputFormatter(RegExp("^[0-9.]*")),
], ],

View File

@ -49,24 +49,37 @@ class _PaymentViewState extends State<PaymentView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
if (!isBusy) if (!isBusy) Navigator.pop(context);
Navigator.pop(context);
return new Future(() => false); return new Future(() => false);
}, },
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
brightness: Brightness.light,
backgroundColor: whiteColor, backgroundColor: whiteColor,
elevation: 0, elevation: 0,
leading: IconButton(icon: Icon(Icons.arrow_back_ios), color: Colors.black87, onPressed: () => Navigator.pop(context),), leading: IconButton(
title: Text(dataTitle(), style: TextStyle(color: Colors.black87),), icon: Icon(Icons.arrow_back_ios),
color: Colors.black87,
onPressed: () => Navigator.pop(context),
),
title: Text(
dataTitle(),
style: TextStyle(color: Colors.black87),
),
), ),
body: Container( body: Container(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 12.0 ), padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 12.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text(dataText() , style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black26, fontSize: 15 ),), Text(
buildStoreConnector(), dataText(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black26,
fontSize: 15),
),
buildStoreConnector(),
verticalSpaceLarge, verticalSpaceLarge,
_buildBodyContent(), _buildBodyContent(),
], ],
@ -76,96 +89,137 @@ class _PaymentViewState extends State<PaymentView> {
); );
} }
String dataTitle() => widget.model.operationType == OperationTypePay ? 'Оплата' : 'Возврат'; String dataTitle() =>
widget.model.operationType == OperationTypePay ? 'Оплата' : 'Возврат';
String dataText() => widget.model.operationType == OperationTypePay ? 'К оплате' : 'К возврату'; String dataText() => widget.model.operationType == OperationTypePay
? 'К оплате'
: 'К возврату';
StoreConnector buildStoreConnector() { StoreConnector buildStoreConnector() {
if(widget.model.mode == SettingModeCalc) { if (widget.model.mode == SettingModeCalc) {
return StoreConnector<AppState, CalcState>( return StoreConnector<AppState, CalcState>(
converter: (store) => store.state.calcState, converter: (store) => store.state.calcState,
builder: (_, vm) { builder: (_, vm) {
return Text('${totalCalc(vm.calcItems)} тнг', style: TextStyle( return Text('${totalCalc(vm.calcItems)} тнг',
fontWeight: FontWeight.bold, style: TextStyle(
color: Colors.black87, fontWeight: FontWeight.bold,
fontSize: 35)); color: Colors.black87,
} fontSize: 35));
); });
} }
return StoreConnector<AppState, KassaState>( return StoreConnector<AppState, KassaState>(
converter: (store) => store.state.kassaState, converter: (store) => store.state.kassaState,
builder: (_, vm) { builder: (_, vm) {
return Text('${totalKassa(vm.kassaItems)} тнг', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black87, fontSize: 35 )); return Text('${totalKassa(vm.kassaItems)} тнг',
} style: TextStyle(
); fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 35));
});
} }
Expanded _buildBodyContent() { Expanded _buildBodyContent() {
return Expanded( return Expanded(
child: Column( child: Column(
children: <Widget>[
Container(
height: 150,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
Container( Expanded(
height: 150, child: BusyButton(
child: Row( title: 'Оплатить картой',
mainAxisAlignment: MainAxisAlignment.spaceEvenly, onPressed: () {
children: <Widget>[ pressPayment('card');
Expanded(child: BusyButton(title: 'Оплатить картой', onPressed:() { pressPayment('card');}, mainColor: greenColor,)), },
horizontalSpaceSmall, mainColor: greenColor,
Expanded(child: BusyButton(title: 'Наличными', onPressed:() { pressPayment('cash');}, mainColor: primaryColor,)), )),
], horizontalSpaceSmall,
), Expanded(
), child: BusyButton(
verticalSpaceLarge, title: 'Наличными',
Expanded(child: Container(),), onPressed: () {
Container(child: BusyButton(title: 'Отмена', onPressed:() { Navigator.pop(context);} , mainColor: redColor,)), pressPayment('cash');
},
mainColor: primaryColor,
)),
], ],
), ),
); ),
verticalSpaceLarge,
Expanded(
child: Container(),
),
Container(
child: BusyButton(
title: 'Отмена',
onPressed: () {
Navigator.pop(context);
},
mainColor: redColor,
)),
],
),
);
} }
pressPayment(String type) async { pressPayment(String type) async {
setState(() { isBusy = true; }); setState(() {
isBusy = true;
});
Dialogs.showLoadingDialog(context, _keyLoader); Dialogs.showLoadingDialog(context, _keyLoader);
try { try {
AppState _state = Redux.store.state; AppState _state = Redux.store.state;
String _token = _state.userState.user.token; String _token = _state.userState.user.token;
String _tradeType = _state.settingState.tradeType; String _tradeType = _state.settingState.tradeType;
String _mode = _state.settingState.mode; String _mode = _state.settingState.mode;
if(_mode == SettingModeCalc){ if (_mode == SettingModeCalc) {
_tradeType = SettingTradeTypeGood; _tradeType = SettingTradeTypeGood;
} }
List<ProductDao> kassaItems = _state.kassaState.kassaItems; List<ProductDao> kassaItems = _state.kassaState.kassaItems;
List<CalcModel> calcItems = _state.calcState.calcItems; List<CalcModel> calcItems = _state.calcState.calcItems;
Response<dynamic> response = await _dataService.sellOrReturn(token: _token, kassaItems: kassaItems, paymentType: type, operationType: widget.model.operationType, tradeType: _tradeType, calcItems: calcItems, mode: _mode ); Response<dynamic> response = await _dataService.sellOrReturn(
token: _token,
kassaItems: kassaItems,
paymentType: type,
operationType: widget.model.operationType,
tradeType: _tradeType,
calcItems: calcItems,
mode: _mode);
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { isBusy = false; }); setState(() {
if(response.operation){ isBusy = false;
});
if (response.operation) {
String message = response.body['message']; String message = response.body['message'];
String check = response.body['check']; String check = response.body['check'];
if(_mode == SettingModeCalc){ if (_mode == SettingModeCalc) {
Redux.store.dispatch(cleanCalcItems); Redux.store.dispatch(cleanCalcItems);
} else if(_mode == SettingModeKassa) { } else if (_mode == SettingModeKassa) {
Redux.store.dispatch(cleanKassaItems); Redux.store.dispatch(cleanKassaItems);
} }
Redux.store.dispatch(checkMoney); Redux.store.dispatch(checkMoney);
_navigatorService.pop(); _navigatorService.pop();
_navigatorService.push(ImageShowRoute, arguments: ImageShowModel(check, message)); _navigatorService.push(ImageShowRoute,
} else if(!response.operation && response.status !=500) { arguments: ImageShowModel(check, message));
} else if (!response.operation && response.status != 500) {
_dialogService.showDialog(description: response.body['message']); _dialogService.showDialog(description: response.body['message']);
} }
} catch(e) { } catch (e) {
//Navigator.of(_keyLoader.currentContext, rootNavigator: true).pop(); //Navigator.of(_keyLoader.currentContext, rootNavigator: true).pop();
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { isBusy = false; }); setState(() {
isBusy = false;
});
} }
} }
String totalKassa(List<ProductDao> kassaItems) { String totalKassa(List<ProductDao> kassaItems) {
num total = 0.0; num total = 0.0;
kassaItems.forEach((element) { kassaItems.forEach((element) {
total+= element.total == null ? 0.0 : element.total.toDouble(); total += element.total == null ? 0.0 : element.total.toDouble();
}); });
return total.toString(); return total.toString();
} }
@ -173,12 +227,12 @@ class _PaymentViewState extends State<PaymentView> {
String totalCalc(List<CalcModel> items) { String totalCalc(List<CalcModel> items) {
num total = 0.0; num total = 0.0;
items.forEach((element) { items.forEach((element) {
if(element.operation == Calculations.MULTIPLY) { if (element.operation == Calculations.MULTIPLY) {
double num1 = element.num1 == null ? 0.0 : double.parse(element.num1); double num1 = element.num1 == null ? 0.0 : double.parse(element.num1);
double num2 = element.num2 == null ? 0.0 : double.parse(element.num2); double num2 = element.num2 == null ? 0.0 : double.parse(element.num2);
total += num1 * num2; total += num1 * num2;
} else { } else {
total+= element.num1 == null ? 0.0 : double.parse(element.num1); total += element.num1 == null ? 0.0 : double.parse(element.num1);
} }
}); });
return total.toString(); return total.toString();
@ -189,4 +243,4 @@ class PaymentModel {
String operationType; String operationType;
String mode; String mode;
PaymentModel({this.mode, this.operationType}); PaymentModel({this.mode, this.operationType});
} }