aman-kassa-flutter/lib/views/payment_nfc/payment_nfc_view.dart

174 lines
6.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/models/calc_model.dart';
import 'package:aman_kassa_flutter/core/models/product_dao.dart';
import 'package:aman_kassa_flutter/core/models/response.dart';
import 'package:aman_kassa_flutter/core/route_names.dart';
import 'package:aman_kassa_flutter/core/services/DataService.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
import 'package:aman_kassa_flutter/redux/actions/calc_actions.dart';
import 'package:aman_kassa_flutter/redux/actions/kassa_actions.dart';
import 'package:aman_kassa_flutter/redux/actions/user_actions.dart';
import 'package:aman_kassa_flutter/redux/constants/operation_const.dart';
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
import 'package:aman_kassa_flutter/redux/state/calc_state.dart';
import 'package:aman_kassa_flutter/redux/state/kassa_state.dart';
import 'package:aman_kassa_flutter/redux/store.dart';
import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:aman_kassa_flutter/shared/ui_helpers.dart';
import 'package:aman_kassa_flutter/views/check/image_show_container.dart';
import 'package:aman_kassa_flutter/views/payment/payment_view.dart';
import 'package:aman_kassa_flutter/views/payment_nfc/widgets/background_view.dart';
import 'package:aman_kassa_flutter/views/payment_nfc/widgets/card_view.dart';
import 'package:aman_kassa_flutter/views/payment_nfc/widgets/phone_view.dart';
import 'package:aman_kassa_flutter/views/payment_nfc/widgets/text_state.dart';
import 'package:aman_kassa_flutter/widgets/components/calculator/calculator.dart';
import 'package:aman_kassa_flutter/widgets/fields/busy_button.dart';
import 'package:aman_kassa_flutter/widgets/loader/Dialogs.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_screenutil/screenutil.dart';
class PaymentNfcView extends StatefulWidget {
final PaymentModel model;
const PaymentNfcView({Key key, this.model}) : super(key: key);
@override
_PaymentNfcViewState createState() => _PaymentNfcViewState();
}
class _PaymentNfcViewState extends State<PaymentNfcView> {
bool isBusy;
bool isPhoneScaled = false;
int status = 0;
@override
void initState() {
super.initState();
isBusy = false;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
if (!isBusy) Navigator.pop(context);
return new Future(() => false);
},
child: Scaffold(
appBar: AppBar(
brightness: Brightness.light,
backgroundColor: purpleColor,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
color: whiteColor,
onPressed: () => Navigator.pop(context),
),
title: Text(
dataTitle(),
style: TextStyle(color: whiteColor),
),
actions: <Widget>[
FlatButton(
onPressed: () {
setState(() {
isPhoneScaled = !isPhoneScaled;
status += 1;
});
},
child: Icon(Icons.add)),
],
),
body: Container(
decoration: BoxDecoration(color: purpleColor),
padding: EdgeInsets.symmetric(
vertical: ScreenUtil().setSp(12.0),
horizontal: ScreenUtil().setSp(12.0)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
dataText(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: whiteColor.withOpacity(0.7),
fontSize: ScreenUtil().setSp(15.0)),
),
buildStoreConnector(),
Expanded(
child: Stack(
children: <Widget>[
BackgroundView(),
TextStateView(
status: status,
),
CardView(
show: isPhoneScaled,
),
PhoneView(scaled: isPhoneScaled, status: status,),
],
),
)
],
),
),
),
);
}
String dataTitle() =>
widget.model.operationType == OperationTypePay ? 'Оплата' : 'Возврат';
String dataText() => widget.model.operationType == OperationTypePay
? 'К оплате'
: 'К возврату';
StoreConnector buildStoreConnector() {
if (widget.model.mode == SettingModeCalc) {
return StoreConnector<AppState, CalcState>(
converter: (store) => store.state.calcState,
builder: (_, vm) {
return Text('${totalCalc(vm.calcItems)} тнг',
style: TextStyle(
fontWeight: FontWeight.bold,
color: whiteColor,
fontSize: 35));
});
}
return StoreConnector<AppState, KassaState>(
converter: (store) => store.state.kassaState,
builder: (_, vm) {
return Text('${totalKassa(vm.kassaItems)} тнг',
style: TextStyle(
fontWeight: FontWeight.bold,
color: whiteColor,
fontSize: 35));
});
}
String totalKassa(List<ProductDao> kassaItems) {
num total = 0.0;
kassaItems.forEach((element) {
total += element.total == null ? 0.0 : element.total.toDouble();
});
return total.toString();
}
String totalCalc(List<CalcModel> items) {
num total = 0.0;
items.forEach((element) {
if (element.operation == Calculations.MULTIPLY) {
double num1 = element.num1 == null ? 0.0 : double.parse(element.num1);
double num2 = element.num2 == null ? 0.0 : double.parse(element.num2);
total += num1 * num2;
} else {
total += element.num1 == null ? 0.0 : double.parse(element.num1);
}
});
return total.toString();
}
}