move apiURL, appToken to libs/consts.dart, refs #9990
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'consts.dart';
|
||||
import 'network.dart';
|
||||
import 'registration.dart';
|
||||
import 'purchase.dart';
|
||||
@@ -16,7 +17,7 @@ String token;
|
||||
pushRoute(BuildContext context, Widget widget) {
|
||||
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
}
|
||||
}
|
||||
|
||||
// Добавление route, с возможностью вернуться к предыдущему экрану.
|
||||
faq(BuildContext context, bool returnToScanner) {
|
||||
@@ -26,7 +27,7 @@ faq(BuildContext context, bool returnToScanner) {
|
||||
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context) {
|
||||
|
||||
|
||||
VoidCallback positiveCalback = () {
|
||||
if (token != null) {
|
||||
deleteToken(token).then((response) {
|
||||
@@ -34,7 +35,7 @@ logout(BuildContext context) {
|
||||
platform.invokeMethod('removeKeys').then((result) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
|
||||
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
@@ -49,12 +50,12 @@ logout(BuildContext context) {
|
||||
}
|
||||
|
||||
forceLogout(BuildContext context) {
|
||||
|
||||
|
||||
deleteToken(token).then((response) {
|
||||
print(response.body);
|
||||
platform.invokeMethod('removeKeys').then((result) {
|
||||
Navigator.of(context).pop();
|
||||
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
|
||||
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
@@ -64,7 +65,7 @@ forceLogout(BuildContext context) {
|
||||
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
||||
/// Может производиться с нескольких экранов (splash, finish_registration).
|
||||
startScanner(BuildContext context) async {
|
||||
|
||||
|
||||
// Канал ловит вызовы методов из "нативной" части приложения.
|
||||
// Могут быть вызваны либо logaut либо faq, либо purchase.
|
||||
if (token != null) {
|
||||
@@ -74,7 +75,7 @@ startScanner(BuildContext context) async {
|
||||
if (call.method == 'logout') {
|
||||
forceLogout(context);
|
||||
} else if (call.method == 'faq') {
|
||||
faq(context, true);
|
||||
faq(context, true);
|
||||
} else {
|
||||
String userString = call.arguments[0];
|
||||
print('user: ${userString}');
|
||||
@@ -84,7 +85,11 @@ startScanner(BuildContext context) async {
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
}
|
||||
});
|
||||
await platform.invokeMethod('startScanner', {'token' : token});
|
||||
await platform.invokeMethod('startScanner', {
|
||||
'token' : token,
|
||||
'url': url,
|
||||
'appToken': appToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +108,4 @@ showYesNoDialog(BuildContext context, String title, String content, VoidCallback
|
||||
new FlatButton(
|
||||
child: new Text('Да'),
|
||||
onPressed: positiveCallback)]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Serious constants
|
||||
const String url = 'http://pos-api-autoclub.dinect.com/20130701/';
|
||||
const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
|
||||
const String appName = "Dinect";
|
||||
|
||||
const String url = 'https://pos-api-ote.dinect.com/20130701/';
|
||||
const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
|
||||
|
||||
// Texts
|
||||
const String merchantIDHint = 'ID магазина';
|
||||
@@ -35,4 +37,4 @@ const Color faqTitlesColor = const Color(0xff404040);
|
||||
const double verticalMargin = 28.0;
|
||||
const double buttonVerticalMargin = 42.0;
|
||||
const double buttonHeight = 48.0;
|
||||
const double iconHeight = 20.0;
|
||||
const double iconHeight = 20.0;
|
||||
|
||||
@@ -9,11 +9,11 @@ void main() {
|
||||
|
||||
class Checker extends StatelessWidget {
|
||||
@override Widget build(BuildContext context) {
|
||||
return new MaterialApp(title: "AutoClub",
|
||||
home: new SplashScreen(),
|
||||
return new MaterialApp(title: appName,
|
||||
home: new SplashScreen(),
|
||||
theme: new ThemeData(
|
||||
primaryColor: primaryColor,
|
||||
accentColor: primaryColor
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
}
|
||||
|
||||
@override getTextWidget() {
|
||||
return new TextField(keyboardType: TextInputType.text, decoration: new InputDecoration.collapsed(hintText: getHint(),
|
||||
return new TextField(keyboardType: TextInputType.number, decoration: new InputDecoration.collapsed(hintText: getHint(),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||
controller: controller,
|
||||
onChanged: (text) => handleUserInput(text));
|
||||
@@ -111,9 +111,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
};
|
||||
|
||||
httpClient.get(url, headers: headers).then((response) {
|
||||
|
||||
|
||||
print(response.body);
|
||||
|
||||
|
||||
Map bonuses = JSON.decode(response.body);
|
||||
String type = bonuses['type'];
|
||||
setState(() {
|
||||
@@ -122,7 +122,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
} else {
|
||||
List amountToBonus = bonuses['amount_to_bonus'];
|
||||
double loyalityVal = (double.parse(amountToBonus[1]) / amountToBonus[0]) * 100;
|
||||
this.loyality = '${loyalityVal.toStringAsFixed(0)}%';
|
||||
this.loyality = '${loyalityVal.toStringAsFixed(0)}%';
|
||||
}
|
||||
});
|
||||
}).catchError((error) {
|
||||
@@ -180,7 +180,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
'doc_id': result,
|
||||
'curr_iso_code': '643',
|
||||
'commit': 'true',
|
||||
'sum_total': sum_total
|
||||
'sum_total': sum_total
|
||||
};
|
||||
|
||||
var headers = {
|
||||
@@ -189,7 +189,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
};
|
||||
|
||||
httpClient.post(url, body: body, headers: headers).then((response) {
|
||||
|
||||
|
||||
print(response.body);
|
||||
Navigator.of(context).pop();
|
||||
pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'] == null ? '' : user['first_name']));
|
||||
@@ -200,4 +200,4 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user