101 lines
2.6 KiB
Dart
101 lines
2.6 KiB
Dart
import 'package:checker/db.dart';
|
||
import 'package:checker/strings.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:checker/screens/splash.dart';
|
||
import 'package:flutter/services.dart';
|
||
|
||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||
|
||
main() {
|
||
|
||
platform.invokeMethod('getFlavor').then((flavor) {
|
||
platform.invokeMethod('getAppTitle').then((title) {
|
||
|
||
String app = flavor; // dinect, autobonus
|
||
String appName= title; // Dinect, Dinect (INT), Autobonus
|
||
|
||
SqliteHelper helper = new SqliteHelper();
|
||
|
||
helper.open().then((_) {
|
||
helper.getLocale().then((locale) {
|
||
if (locale == null) {
|
||
initWithSystemValue(app, appName, helper);
|
||
} else {
|
||
start(app, appName, locale, helper);
|
||
}
|
||
});
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
initWithSystemValue(String app, String name, SqliteHelper helper) {
|
||
platform.invokeMethod('getLocale').then((locale) {
|
||
helper.getSettings(false).then((settings) {
|
||
if (settings == null) {
|
||
createSettingsTable(app, name, locale, helper);
|
||
} else {
|
||
start(app, name, locale, helper);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
createSettingsTable(String app, String name, String locale, SqliteHelper helper) {
|
||
platform.invokeMethod('getCurrency').then((currency) {
|
||
helper.createAppInfo(currency).then(() {
|
||
start(app, name, locale, helper);
|
||
});
|
||
});
|
||
}
|
||
|
||
start(String app, String name, String locale, SqliteHelper helper) {
|
||
StringsLocalization.load(locale).then((_) {
|
||
runApp(new Checker(app, name, locale, helper));
|
||
});
|
||
}
|
||
|
||
class Checker extends StatefulWidget {
|
||
|
||
/// Класс для работы с бд
|
||
final SqliteHelper helper;
|
||
|
||
/// Тип сборки. Определяет, какие брать ресурсы (цвета, картинки)
|
||
final String app;
|
||
|
||
/// Отображаемое в заголовке приложения названия (когда показывается список запущенных приложений)
|
||
final String appName;
|
||
|
||
/// Локаль приложения
|
||
final String locale;
|
||
|
||
Checker(this.app, this.appName, this.locale, this.helper);
|
||
|
||
@override
|
||
State<StatefulWidget> createState() => new CheckerState(
|
||
this.app,
|
||
this.appName,
|
||
this.locale,
|
||
this.helper);
|
||
}
|
||
|
||
class CheckerState extends State<Checker> {
|
||
|
||
SqliteHelper helper;
|
||
String app;
|
||
String appName;
|
||
String locale;
|
||
|
||
String token;
|
||
|
||
CheckerState(this.app, this.appName, this.locale, this.helper);
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return new MaterialApp(
|
||
title: appName,
|
||
home: new SplashScreen(helper, app)
|
||
);
|
||
}
|
||
}
|