91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:flutter/services.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'dart:async';
|
||
import 'dart:convert';
|
||
|
||
import 'main.dart';
|
||
import 'registration.dart';
|
||
import 'activate_token.dart';
|
||
import 'purchase.dart';
|
||
|
||
class SplashScreen extends StatelessWidget {
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
|
||
// Появляется splash screen, проверяется токен.
|
||
new Future.delayed(const Duration(milliseconds: 500), () {
|
||
showNextScreen(context);
|
||
// startScanner(context);
|
||
// pushRoute(context, new PurchaseScreen(null));
|
||
});
|
||
|
||
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));
|
||
}
|
||
|
||
/// Запуск следующего экрана приложения.
|
||
showNextScreen(BuildContext context) async {
|
||
|
||
token = await platform.invokeMethod('getToken');
|
||
print('token: $token');
|
||
|
||
// В случае, если в приложении отсутствует токен,
|
||
// необходимо запустить регистрацию кассы.
|
||
if (token == null) {
|
||
pushRoute(context, new RegistrationScreen());
|
||
} else {
|
||
|
||
checkTokenStatus(context).then((statusResponse) {
|
||
handleStatusResponse(context, statusResponse);
|
||
}).catchError((error) {
|
||
print('Handle exception!');
|
||
print(error.toString());
|
||
return false;
|
||
});
|
||
}
|
||
}
|
||
|
||
startRegistration() async {
|
||
|
||
}
|
||
|
||
handleStatusResponse(BuildContext context, var statusResponse) async {
|
||
int code = statusResponse.statusCode;
|
||
print('resp: ${code}');
|
||
|
||
if (code == 404) {
|
||
platform.invokeMethod('removeKeys').then((result) {
|
||
print('try to start registration');
|
||
pushRoute(context, new RegistrationScreen());
|
||
});
|
||
} else {
|
||
|
||
Map statusResponseMap = JSON.decode(statusResponse.body);
|
||
bool active = statusResponseMap['active'];
|
||
|
||
if (active) {
|
||
startScanner(context);
|
||
} else {
|
||
createToken(await platform.invokeMethod('getMerchantID')).then((response) {
|
||
print('response.body: ${response.body}');
|
||
|
||
if (response.statusCode == 409) {
|
||
pushRoute(context, new FinishRegistrationScreen());
|
||
} else {
|
||
startRegistration();
|
||
}
|
||
|
||
}).catchError((error) {
|
||
platform.invokeMethod('removeKeys').then((result) => pushRoute(context, new RegistrationScreen()));
|
||
});
|
||
}
|
||
}
|
||
}
|
||
} |