Получение информации о пользователе, разные исправления

This commit is contained in:
Ivan Murashov
2017-07-25 21:27:50 +03:00
parent 8738fbfd39
commit 313dc307dc
16 changed files with 290 additions and 161 deletions

View File

@@ -34,8 +34,7 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
getHintLabel(),
getDecoratedTextWidget(),
getMessage(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin),
buildRaisedButton(context, _tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ', () => handleTap()))
buildRaisedButton(context, _tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ', () => handleTap())
]);
}

View File

@@ -46,7 +46,8 @@ abstract class BaseState<T> extends State<T> {
String getHint();
faq() {
pushRoute(context, new FAQScreen());
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new FAQScreen());
Navigator.of(context).push(route);
}
/// Метод возвращает контейнер с отступами, который содержит картинку с логотипом.
@@ -101,7 +102,7 @@ abstract class BaseState<T> extends State<T> {
/// Метод возвращает BoxDecoration для _getDecoratedInputField
getDecoraionForTextWidget() {
return new BoxDecoration(color: getTextFilledBackground(),
border: new Border.all(color: textBorderColor, width: 1.0,),
border: new Border.all(color: textBorderColor, width: 1.0),
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
}

View File

@@ -11,21 +11,25 @@ class Entry {
}
class EntryItem extends StatelessWidget {
const EntryItem(this.entry);
final Entry entry;
Widget _buildTiles(Entry root) {
return new ExpansionTile(
Widget _buildTiles(BuildContext context, Entry root) {
EdgeInsets margin = new EdgeInsets.only(left: 20.0, right: 20.0);
TextStyle titleStyle = Theme.of(context).textTheme.button.copyWith(fontWeight: FontWeight.bold, color: faqTitlesColor);
return new Container(margin: margin, child: new Card(child: new ExpansionTile(
key: new PageStorageKey<Entry>(root),
title: new Text(root.title),
children: [new Text(root.text)]
);
title:new Text(root.title, style: titleStyle),
children: [new Container(margin: margin, padding: new EdgeInsets.only(top: 12.0, bottom: 20.0),
child: new Text(root.text, style: new TextStyle(fontWeight: FontWeight.w300, color: faqGrey, fontSize: 14.0)),
decoration: new BoxDecoration(border: new Border(top: new BorderSide(color: greyTextColor, width: 0.5))))]
)));
}
@override
Widget build(BuildContext context) {
return _buildTiles(entry);
return _buildTiles(context, entry);
}
}
@@ -34,10 +38,10 @@ class FAQScreen extends StatelessWidget {
AppBar getAppBar(BuildContext context) {
return new AppBar(title: new Text('FAQ', style: new TextStyle(fontSize: 18.0)),
backgroundColor: primaryColor, actions: <Widget>[getLogoutButton()]);
backgroundColor: primaryColor, actions: <Widget>[getLogoutButton(context)]);
}
getLogoutButton() {
getLogoutButton(BuildContext context) {
return new IconButton(icon: new Image.asset(logout_png, height: iconHeight, width: iconHeight), onPressed: () => logout(context));
}
@override
@@ -54,10 +58,10 @@ class FAQScreen extends StatelessWidget {
/// Список с контентом
final List<Entry> data = <Entry>[
new Entry('Регистрация', registrationGuide),
new Entry('Использование', usageGuide),
new Entry('Контакты поддержки', supportGuide),
new Entry('Использование', commonGuide)
new Entry('РЕГИСТРАЦИЯ', registrationGuide),
new Entry('ИСПОЛЬЗОВАНИЕ', usageGuide),
new Entry('КОНТАКТЫ ПОДДЕРЖКИ', supportGuide),
new Entry('ОБЩАЯ ИНФОРМАЦИЯ', commonGuide)
];
/// TODO: Отформатировать строки

View File

@@ -23,7 +23,9 @@ const String splash_png = 'assets/splash.png';
const String logout_png = 'assets/logout.png';
const String activate_token_bg_png = 'assets/activate_token_message_background.png';
const String active_token_bg_png = 'assets/active_token_message_background.png';
const String expansion_icon_png = 'assets/expansion_icon.png';
const String powered_by_dinect_splash_png = 'assets/powered_by_dinect_splash.png';
const String powered_by_dinect_png = 'assets/powered_by_dinect.png';
// Colors
const Color primaryColor = const Color(0xffeb0004);
const Color greyTextColor = const Color(0xffa5a5a5);
@@ -31,7 +33,8 @@ const Color textBorderColor = const Color(0xffcfd8dc);
const Color tokenActiveTextColor = const Color(0xff1f5a1f);
const Color tokenActivateTextColor = const Color(0xff4e3a19);
const Color greenBackground = const Color(0xff8ae28a);
const Color faqGrey = const Color(0xff5b5b5b);
const Color faqTitlesColor = const Color(0xff404040);
// Dimens
const double verticalMargin = 28.0;
const double buttonVerticalMargin = 42.0;
@@ -62,44 +65,68 @@ startScanner(BuildContext context) async {
// Канал ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logaut либо faq, либо purchase.
platform.setMethodCallHandler((MethodCall call) async {
if (call.method == 'foo') {
logout(context);
} else {
pushRoute(context, new PurchaseScreen());
}
if (token != null) {
platform.setMethodCallHandler((MethodCall call) async {
return result;
if (call.method == 'foo') {
logout(context);
} else {
});
var card = call.arguments;
print('card: ' + card);
String url = 'http://pos-api-int.dinect.com/20130701/users/?auto=${card}';
print('url: ' + url);
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
httpClient.get(url, headers: headers).then((response) {
print(response.body);
List usersList = JSON.decode(response.body);
if (usersList.length > 0) {
pushRoute(context, new PurchaseScreen(usersList[0], card));
}
}).catchError((error) {
print(error.toString());
});
}
});
}
Navigator.of(context).pop();
await platform.invokeMethod('startScanner');
}
logout(BuildContext context) {
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
print(url);
httpClient.delete(url).then((response) {
print(response.body);
const platform = const MethodChannel('com.dinect.checker/instance_id');
platform.invokeMethod('removeKeys');
pushRoute(context, new RegistrationScreen());
}).catchError((error) {
print(error.toString());
});
if (token != null) {
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
print(url);
httpClient.delete(url).then((response) {
print(response.body);
const platform = const MethodChannel('com.dinect.checker/instance_id');
platform.invokeMethod('removeKeys');
Navigator.of(context).pop();
pushRoute(context, new RegistrationScreen());
}).catchError((error) {
print(error.toString());
});
} else {
Navigator.of(context).pop();
}
}
/// Навигация по приложению.
/// widget - следующий экран приложения.
pushRoute(BuildContext context, Widget widget) {
Navigator.of(context).pushReplacement(new MaterialPageRoute<Null>(
builder: (BuildContext context) {
return widget;
}));
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
Navigator.of(context).pushReplacement(route);
}
class Checker extends StatelessWidget {
@@ -111,4 +138,6 @@ class Checker extends StatelessWidget {
accentColor: primaryColor
));
}
}
}

View File

@@ -9,12 +9,41 @@ import 'purchase_success.dart';
/// Экран проведения покупки.
class PurchaseScreen extends StatefulWidget {
@override State createState() => new PurchaseScreenState<PurchaseScreen>();
PurchaseScreen(this.response, this.card);
Map response;
String card;
@override State createState() => new PurchaseScreenState<PurchaseScreen>(response, card);
}
class PurchaseScreenState<T> extends BaseState<T> {
class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
PurchaseScreenState(Map user, String card) {
this.user = user;
this.card = card;
getLoyality(user['loyalty_url']);
}
Map user;
String card;
String integerPart = '', fractionalPart = '';
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']),
getValueWithTitle('Карта', card),
getValueWithTitle('Вознаграждение', loyality),
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 String getTitle() {
return "Проведение покупки";
@@ -25,24 +54,7 @@ class PurchaseScreenState<T> extends BaseState<T> {
}
@overide getMenuButtons(BuildContext context) {
return <Widget>[
new getFaqButton(),
new getLogoutButton()
];
}
@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()));
return <Widget>[getFaqButton(), getLogoutButton()];
}
@override Color getTextFilledBackground() {
@@ -71,6 +83,35 @@ class PurchaseScreenState<T> extends BaseState<T> {
});
}
getLoyality(String url) {
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
httpClient.get(url, headers: headers).then((response) {
print(response.body);
Map bonuses = JSON.decode(response.body);
String type = bonuses['type'];
setState(() {
if (type == 'amount') {
this.loyality = user['discount'];
} else {
List bonusToAmount = bonuses['bonus_to_amount'];
this.loyality = (bonusToAmount[1].toInt() / bonusToAmount[0].toInt() ).toString();
}
});
}).catchError((error) {
print(error.toString());
});
}
_buildSum() {
String temporaryInteger = integerPart;
String temporaryFractional = fractionalPart;
@@ -84,6 +125,7 @@ class PurchaseScreenState<T> extends BaseState<T> {
_purchase(BuildContext context) {
String val = _buildSum();
print(val);
showDialog(context: context, child: new AlertDialog(
title: new Text('Подтверждение'),
content: new Text('Вы подтверждаете покупку на ${val} руб?'),
@@ -97,7 +139,8 @@ class PurchaseScreenState<T> extends BaseState<T> {
new FlatButton(
child: new Text('Да'),
onPressed: () {
pushRoute(context, new PurchaseSuccessScreen(val));
Navigator.of(context).pop();
pushRoute(context, new PurchaseSuccessScreen(val, user['first_name']));
},
)
]));

View File

@@ -8,21 +8,22 @@ import 'purchase.dart';
/// Экран проведения покупки.
class PurchaseSuccessScreen extends StatefulWidget {
String val = '';
PurchaseSuccessScreen(this.val, this.name);
String val;
String name;
PurchaseSuccessScreen(String val) {
this.val = val;
}
@override State createState() => new PurchaseSuccessScreenState(val);
@override State createState() => new PurchaseSuccessScreenState(val, name);
}
class PurchaseSuccessScreenState<T> extends PurchaseScreenState<T> {
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
String val = '';
PurchaseSuccessScreenState(this.sum, this.username);
PurchaseSuccessScreenState(String val) {
this.val = val;
String sum;
String username;
@overide getMenuButtons(BuildContext context) {
return <Widget>[getFaqButton(), getLogoutButton()];
}
@override String getTitle() {
@@ -31,7 +32,7 @@ class PurchaseSuccessScreenState<T> extends PurchaseScreenState<T> {
@override Widget getScreenContent() {
return new Column(children: <Widget>[
getValueWithTitle('Покупатель', 'Знаменитый Рокер Паук'),
getValueWithTitle('Покупатель', username),
getSuccessMessage(),
new Expanded(child: new Center()),
buildButton(new EdgeInsets.only(bottom: 74.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'СКАНИРОВАТЬ', () => startScanner(context)))
@@ -41,7 +42,7 @@ class PurchaseSuccessScreenState<T> extends PurchaseScreenState<T> {
getSuccessMessage() {
return new Row(children: <Widget>[new Expanded(child: new Container(margin: new EdgeInsets.only(top: 20.0), height: 64.0,
decoration: new BoxDecoration(color: greenBackground),
child: new Center(child: new Text('Покупка на сумму ${val} руб. проведена', textAlign: TextAlign.center,
child: new Center(child: new Text('Покупка на сумму ${sum} руб. проведена', textAlign: TextAlign.center,
style: new TextStyle(fontWeight: FontWeight.bold, color: tokenActiveTextColor)))))]);
}

View File

@@ -33,8 +33,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
getLogo(),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin),
buildRaisedButton(context, 'ЗАРЕГИСТРИРОВАТЬ', _isValidMerchantID() && !loading ? () => _registerShop(context) : null))]))
new Container(margin: new EdgeInsets.only(top: 36.0), child: buildRaisedButton(context, 'ЗАРЕГИСТРИРОВАТЬ', _isValidMerchantID() && !loading ? () => _registerShop(context) : null))]))
].reversed.toList()));
}

View File

@@ -16,9 +16,18 @@ class SplashScreen extends StatelessWidget {
// Появляется splash screen, проверяется токен.
new Future.delayed(const Duration(milliseconds: 500), () {
showNextScreen(context);
// startScanner(context);
// pushRoute(context, new PurchaseScreen(null));
});
return new Image.asset(splash_png, fit: BoxFit.cover);
return new Stack(children: <Widget>[new Container(padding: new EdgeInsets.only(left: 48.0, right: 48.0), decoration: getSplashBg()),
new Align(alignment: FractionalOffset.bottomRight, child:
new Container(margin: new EdgeInsets.only(right: 11.0, bottom: 5.0), child: new Image.asset(powered_by_dinect_splash_png, height: 16.0, width: 122.0)))]);
}
Decoration getSplashBg() {
return new BoxDecoration(image: new DecorationImage(
image: new ExactAssetImage(splash_png), fit: BoxFit.cover));
}
/// Запуск следующего экрана приложения.