Вынес работу с сетью и общие методы в отдельные файлы

This commit is contained in:
kifio
2017-07-27 08:45:47 +03:00
parent 73e139f925
commit d0b5b17334
11 changed files with 256 additions and 206 deletions

View File

@@ -1,12 +1,12 @@
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'main.dart';
import 'common.dart';
import 'network.dart';
import 'consts.dart';
import 'registration.dart';
import 'activate_token.dart';
import 'purchase.dart';
class SplashScreen extends StatelessWidget {
@@ -20,14 +20,18 @@ class SplashScreen extends StatelessWidget {
// pushRoute(context, new PurchaseScreen(null));
});
return new Stack(children: <Widget>[new Container(padding: new EdgeInsets.only(left: 48.0, right: 48.0), decoration: getSplashBg()),
return new Stack(children: <Widget>[getBackgroundContainer(),
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));
getBackgroundContainer() {
const margin = 48.0;
return new Container(padding: new EdgeInsets.only(left: margin, right: margin), decoration: getSplashBackground());
}
getSplashBackground() {
return new BoxDecoration(image: new DecorationImage(image: new ExactAssetImage(splash_png), fit: BoxFit.cover));
}
/// Запуск следующего экрана приложения.
@@ -42,20 +46,18 @@ class SplashScreen extends StatelessWidget {
pushRoute(context, new RegistrationScreen());
} else {
checkTokenStatus(context).then((statusResponse) {
checkTokenStatus(token).then((statusResponse) {
handleStatusResponse(context, statusResponse);
}).catchError((error) {
print('Handle exception!');
print(error.toString());
return false;
});
}
}
startRegistration() async {
}
// Обработка ответа.
// В случае, если токен был удален может прийти active: false, либо 404.
// Если токен не активен, попробовать создать его еще раз. В случае успешного создания токена удалить его и перейти на экран регистрации
handleStatusResponse(BuildContext context, var statusResponse) async {
int code = statusResponse.statusCode;
print('resp: ${code}');
@@ -73,13 +75,20 @@ class SplashScreen extends StatelessWidget {
if (active) {
startScanner(context);
} else {
createToken(await platform.invokeMethod('getMerchantID')).then((response) {
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 {
startRegistration();
deleteToken(token).then((response) async {
print(response.body);
await platform.invokeMethod('removeKeys');
Navigator.of(context).pop(); // Убираем текущий route
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
}).catchError((error) {
print(error.toString());
});
}
}).catchError((error) {