Files
checker/lib/main.dart

106 lines
3.6 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 textFieldBackground = const Color(0xffefefef);
const Color tokenActiveTextColor = const Color(0xff1f5a1f);
const Color tokenActivateTextColor = const Color(0xff4e3a19);
// Margins
const double verticalMargin = 28.0;
// 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 {
const platform = const MethodChannel('com.dinect.checker/instance_id');
// Канал слушает ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logaut либо faq, либо purchase.
platform.setMethodCallHandler((MethodCall call) async {
if (call.method == 'foo') {
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
httpClient.delete(url).then((response) {
print(response.body);
}).catchError((error) {
print(error.toString());
});
pushRoute(context, new RegistrationScreen());
} else {
pushRoute(context, new PurchaseScreen());
}
return result;
});
await platform.invokeMethod('startScanner');
}
/// Навигация по приложению.
/// 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
));
}
}