Поправил много неприятных косяков

This commit is contained in:
Ivan Murashov
2017-07-27 18:47:42 +03:00
parent 303f3e2ff3
commit 311d532898
9 changed files with 116 additions and 69 deletions

View File

@@ -55,7 +55,7 @@ abstract class BaseState<T> extends State<T> {
double horizontalMargin = 8.0;
return new Container(margin: new EdgeInsets.only(top: horizontalMargin, bottom: horizontalMargin, left: verticalMargin, right: verticalMargin),
child: new Row(crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[new Text(getHintText(), overflow: TextOverflow.ellipsis, textAlign: TextAlign.left,
children: <Widget>[new Text(getHintText(), textAlign: TextAlign.left,
style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : primaryColor, fontSize: 14.0))]));
}
@@ -112,7 +112,6 @@ abstract class BaseState<T> extends State<T> {
onChanged: (text) => handleUserInput(text));
}
/// Индикация ...
Widget getProgressIndicator() {
return new Center(child: loading ? new CircularProgressIndicator() : null);
}
@@ -121,7 +120,7 @@ abstract class BaseState<T> extends State<T> {
return new Container(padding: new EdgeInsets.only(left: verticalMargin, right: verticalMargin, top: 18.0),
child: new Column(children: <Widget>[
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(title, textAlign: TextAlign.left, style: new TextStyle(color: greyTextColor, fontSize: 14.0))]),
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0))])
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Expanded(child: new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0)))])
]));
}

View File

@@ -31,8 +31,11 @@ logout(BuildContext context) {
if (token != null) {
deleteToken(token).then((response) {
print(response.body);
platform.invokeMethod('removeKeys');
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
platform.invokeMethod('removeKeys').then((result) {
Navigator.of(context).pop();
Navigator.of(context).pop();
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
});
}).catchError((error) {
print(error.toString());
});
@@ -45,6 +48,19 @@ logout(BuildContext context) {
showYesNoDialog(context, 'Подтверждение', 'Вы действительно хотите выйти и ввести другой номер магазина?', positiveCalback);
}
forceLogout(BuildContext context) {
deleteToken(token).then((response) {
print(response.body);
platform.invokeMethod('removeKeys').then((result) {
Navigator.of(context).pop();
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
});
}).catchError((error) {
print(error.toString());
});
}
/// Запуск спецефичной для каждой платформы части приложения - сканера.
/// Может производиться с нескольких экранов (splash, finish_registration).
startScanner(BuildContext context) async {
@@ -56,7 +72,7 @@ startScanner(BuildContext context) async {
print('call.method: ${call.method}');
if (call.method == 'logout') {
logout(context);
forceLogout(context);
} else if (call.method == 'faq') {
faq(context, true);
} else {
@@ -68,9 +84,8 @@ startScanner(BuildContext context) async {
Navigator.of(context).pushReplacement(route);
}
});
await platform.invokeMethod('startScanner', {'token' : token});
}
await platform.invokeMethod('startScanner');
}
// Запуск диалога с двумя кнопками

View File

@@ -32,8 +32,4 @@ deleteToken(String token) async {
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
print(url);
return httpClient.delete(url);
}
// Удалить токены
// 57e0d09aa935252d2a3463ebc1d61501608a6af9
// f1355ea87375c173695b57afa72f78fedbe5b6c3
}

View File

@@ -35,17 +35,16 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
String loyality = '';
@override Widget getScreenContent() {
return new Container(height: 412.0,
child: new ListView(reverse: true, children: <Widget>[
new Column(children: <Widget>[
getValueWithTitle('ФИО', user['first_name']),
return new Column(
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
getValueWithTitle('ФИО', user['first_name'] == null ? '' : user['first_name']),
getValueWithTitle('Карта', card),
getValueWithTitle('Вознаграждение', loyality),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => onPurchaseClick(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
].reversed.toList()));
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))
]))]);
}
@override String getTitle() {
@@ -68,7 +67,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@override handleUserInput(String tmpString) {
setState(() {
tmpString = tmpString.replaceAll('-', '');
tmpString = tmpString.replaceAll(', ', '');
tmpString = tmpString.replaceAll(',', '');
print(tmpString);
if (tmpString.contains('.')) {
int dotIndex = tmpString.indexOf('.');
@@ -88,10 +87,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
getLoyality(String url) {
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
print(url);
print(token);
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
httpClient.get(url, headers: headers).then((response) {
@@ -102,11 +104,15 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
setState(() {
if (type == 'amount') {
this.loyality = user['discount'];
this.loyality = '${user['discount']}%';
} else {
List bonusToAmount = bonuses['bonus_to_amount'];
this.loyality = (bonusToAmount[1].toInt() / bonusToAmount[0].toInt() ).toString();
List amountToBonus = bonuses['amount_to_bonus'];
// print(amountToBonus[0]);
// print(amountToBonus[1]);
this.loyality = '${(amountToBonus[0] / double.parse(amountToBonus[1])).toStringAsFixed(0)}%';
}
});
}).catchError((error) {
@@ -170,7 +176,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
print(response.body);
Navigator.of(context).pop();
pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name']));
pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'] == null ? '' : user['first_name']));
}).catchError((error) {
print(error.toString());

View File

@@ -25,14 +25,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
/// Высота контейнера задана для того, чтобы элементы располагались вверху экрана
/// и список скроллился снизу вверх при открытии клавиатуры.
@override Widget getScreenContent() {
return new Container(height: 332.0,
child: new ListView(reverse: true, children: <Widget>[
return new Container(
child: new ListView(children: <Widget>[
new Center(child: new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getDecoratedTextWidget(),
new Container(margin: new EdgeInsets.only(top: 36.0), child: buildRaisedButton(context, 'ЗАРЕГИСТРИРОВАТЬ', _isValidMerchantID() && !loading ? () => _registerShop(context) : null))]))
].reversed.toList()));
]));
}
/// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов.

View File

@@ -16,8 +16,6 @@ class SplashScreen extends StatelessWidget {
// Появляется splash screen, проверяется токен.
new Future.delayed(const Duration(milliseconds: 500), () {
showNextScreen(context);
// startScanner(context);
// pushRoute(context, new PurchaseScreen(null));
});
return new Stack(children: <Widget>[getBackgroundContainer(),
@@ -45,7 +43,6 @@ class SplashScreen extends StatelessWidget {
if (token == null) {
pushRoute(context, new RegistrationScreen());
} else {
checkTokenStatus(token).then((statusResponse) {
handleStatusResponse(context, statusResponse);
}).catchError((error) {
@@ -77,23 +74,23 @@ class SplashScreen extends StatelessWidget {
} else {
createToken(await platform.invokeMethod('getMerchantID'), await platform.invokeMethod('getPosID')).then((response) {
print('response.body: ${response.body}');
if (response.statusCode == 409) {
pushRoute(context, new FinishRegistrationScreen());
} else {
deleteToken(token).then((response) {
print(response.body);
platform.invokeMethod('removeKeys');
Navigator.of(context).pop(); // Убираем текущий route
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
}).catchError((error) {
print(error.toString());
} else if (response.statusCode == 201) {
platform.invokeMethod('removeKeys').then((result) {
Map parsedMap = JSON.decode(result);
String t = parsedMap['token'];
deleteToken(t).then((response) {
print(response.body);
Navigator.of(context).pop(); // Убираем текущий route
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
}).catchError((error) {
print(error.toString());
});
});
}
}).catchError((error) {
platform.invokeMethod('removeKeys').then((result) => pushRoute(context, new RegistrationScreen()));
});
}).catchError((error) => print(error.toString()));
}
}
}