Files
checker/lib/main.dart
2017-07-24 19:45:04 +03:00

114 lines
3.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'splash.dart';
import 'registration.dart';
import 'dart:async';
import 'dart:convert';
import 'purchase.dart';
/// Главный класс приложения.
/// Здесь распоосложены константы и некоторые методы, которые могут вызываться с разных экранов приложения.
// Serious constants
const String intUrl = 'https://pos-api-int.dinect.com/20130701/';
const String intToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
// Hints
const String merchantIDHint = 'ID магазина';
const String posIDHint = 'Номер кассы';
// Assets
const String logo_png = 'assets/registration_logo.png';
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';
// Colors
const Color primaryColor = const Color(0xffeb0004);
const Color greyTextColor = const Color(0xffa5a5a5);
const Color textBorderColor = const Color(0xffcfd8dc);
const Color tokenActiveTextColor = const Color(0xff1f5a1f);
const Color tokenActivateTextColor = const Color(0xff4e3a19);
const Color greenBackground = const Color(0xff8ae28a);
// Dimens
const double verticalMargin = 28.0;
const double buttonVerticalMargin = 42.0;
const double buttonHeight = 48.0;
const double iconHeight = 20.0;
const platform = const MethodChannel('com.dinect.checker/instance_id');
// HttpClient
final httpClient = createHttpClient();
/// Токен кассы. Инициализируется при регистрации.
String token;
/// Точка входа в приложение.
void main() {
runApp(new Checker());
}
/// Проверка статуса токена. Токен может быть активирован, либо не активирован.
checkToken(BuildContext context) async {
return httpClient.get(intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken);
}
/// Запуск спецефичной для каждой платформы части приложения - сканера.
/// Может производиться с нескольких экранов (splash, finish_registration).
startScanner(BuildContext context) async {
// Канал слушает ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logaut либо faq, либо purchase.
platform.setMethodCallHandler((MethodCall call) async {
if (call.method == 'foo') {
logout(context);
} else {
pushRoute(context, new PurchaseScreen());
}
return result;
});
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());
});
}
/// Навигация по приложению.
/// widget - следующий экран приложения.
pushRoute(BuildContext context, Widget widget) {
Navigator.of(context).pushReplacement(new MaterialPageRoute<Null>(
builder: (BuildContext context) {
return widget;
}));
}
class Checker extends StatelessWidget {
@override Widget build(BuildContext context) {
return new MaterialApp(title: "AutoClub",
home: new SplashScreen(),
theme: new ThemeData(
primaryColor: primaryColor,
accentColor: primaryColor
));
}
}