Files
checker/lib/purchase.dart
2017-07-24 19:45:04 +03:00

109 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'dart:async';
import 'main.dart';
import 'base_state.dart';
import 'purchase_success.dart';
/// Экран проведения покупки.
class PurchaseScreen extends StatefulWidget {
@override State createState() => new PurchaseScreenState<PurchaseScreen>();
}
class PurchaseScreenState<T> extends BaseState<T> {
PurchaseScreenState() {
}
String integerPart = '', fractionalPart = '';
@override String getTitle() {
return "Проведение покупки";
}
@override getHint() {
return 'Сумма';
}
@overide getMenuButtons(BuildContext context) {
return <Widget>[
new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {}),
new IconButton(icon: new Image.asset(logout_png, height: iconHeight, width: iconHeight), onPressed: () => logout(context))
];
}
@override Widget getScreenContent() {
return new Container(height: 412.0,
child: new ListView(reverse: true, children: <Widget>[
new Column(children: <Widget>[
getValueWithTitle('ФИО', 'Знаменитый Рокер Паук'),
getValueWithTitle('Карта', 'B0399900702'),
getValueWithTitle('Вознаграждение', '100%'),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => _purchase(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
].reversed.toList()));
}
@override Color getTextFilledBackground() {
return Colors.white;
}
/// Смена состояния экрана при изменении текста в поле ввода.
@override handleUserInput(String tmpString) {
setState(() {
tmpString = tmpString.replaceAll('-', '');
tmpString = tmpString.replaceAll(', ', '');
print(tmpString);
if (tmpString.contains('.')) {
int dotIndex = tmpString.indexOf('.');
integerPart = tmpString.substring(0, dotIndex);
fractionalPart = tmpString.substring(dotIndex + 1, tmpString.length);
if (fractionalPart.length > 2) {
fractionalPart = fractionalPart.substring(0, 2);
}
controller.text = '${integerPart}.${fractionalPart}';
} else {
integerPart = tmpString;
controller.text = tmpString;
}
textFieldValue = controller.text;
});
}
_buildSum() {
String temporaryInteger = integerPart;
String temporaryFractional = fractionalPart;
while (temporaryFractional.length < 2) {
temporaryFractional = temporaryFractional + '0';
}
return temporaryInteger + '.' + temporaryFractional;
}
_purchase(BuildContext context) {
String val = _buildSum();
showDialog(context: context, child: new AlertDialog(
title: new Text('Подтверждение'),
content: new Text('Вы подтверждаете покупку на ${val} руб?'),
actions: <Widget>[
new FlatButton(
child: new Text('Нет'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('Да'),
onPressed: () {
pushRoute(context, new PurchaseSuccessScreen(val));
},
)
]));
}
}