Сделал возможность переключаться между приложениями и добавлять новые приложения практически не меняя код
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:checker/resources.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'consts.dart';
|
||||
@@ -9,6 +11,9 @@ import 'strings.dart';
|
||||
|
||||
abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
|
||||
/// Тип сборки. Определяет, какие брать ресурсы (цвета, картинки)
|
||||
String app;
|
||||
|
||||
/// Ожидание ответа от сервера.
|
||||
bool loading = false;
|
||||
|
||||
@@ -19,13 +24,42 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
String textFieldValue = '';
|
||||
|
||||
@override Widget build(BuildContext ctx) {
|
||||
return new Scaffold(appBar: getAppBar(),
|
||||
|
||||
platform.invokeMethod('getLocale').then((locale) {
|
||||
Intl.defaultLocale = locale;
|
||||
if (app == null) {
|
||||
platform.invokeMethod('getFlavor').then((flavor) {
|
||||
setState(() {
|
||||
app = flavor;
|
||||
onStart();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return getMainWidget();
|
||||
}
|
||||
|
||||
Widget getMainWidget() {
|
||||
return app == null ? getBackground() : new Scaffold(appBar: getAppBar(),
|
||||
body: new Stack(children: <Widget>[
|
||||
getScreenContent(),
|
||||
new Center(child: loading ? new CircularProgressIndicator() : null)
|
||||
]));
|
||||
}
|
||||
|
||||
Widget getBackground() {
|
||||
return new Container(
|
||||
decoration: new BoxDecoration(
|
||||
image: new DecorationImage(
|
||||
image: new ExactAssetImage(Resources.getSplash(app)),
|
||||
fit: BoxFit.cover)));
|
||||
}
|
||||
|
||||
void onStart() {
|
||||
|
||||
}
|
||||
|
||||
/// Возвращает контейнер с всеми виджетами экрана.
|
||||
Widget getScreenContent();
|
||||
|
||||
@@ -34,7 +68,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
|
||||
AppBar getAppBar() {
|
||||
return new AppBar(title: new Text(getTitle(), style: new TextStyle(fontSize: 18.0)),
|
||||
backgroundColor: primaryColor, actions: getMenuButtons());
|
||||
backgroundColor: Resources.getPrimaryColor(app), actions: getMenuButtons());
|
||||
}
|
||||
|
||||
List<Widget> getMenuButtons() {
|
||||
@@ -55,7 +89,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
return new Container(margin: new EdgeInsets.only(top: horizontalMargin, bottom: horizontalMargin, left: verticalMargin, right: verticalMargin),
|
||||
child: new Row(crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[new Text(getHintString(), textAlign: TextAlign.left,
|
||||
style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : primaryColor, fontSize: 14.0))]));
|
||||
style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : Resources.getLogo(app), fontSize: 14.0))]));
|
||||
}
|
||||
|
||||
/// Возвращает подсказку, либо ошибку, если введенные в поле ввода данные неверны.
|
||||
@@ -118,14 +152,14 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
return new RaisedButton(child: new Text(text,
|
||||
style: new TextStyle(color: Colors.white)),
|
||||
onPressed: onPressed,
|
||||
color: buttonColor);
|
||||
color: Resources.getButtonColor(app));
|
||||
}
|
||||
|
||||
/// Метод возвращает контейнер с отступами, который содержит картинку с логотипом.
|
||||
Widget getLogo() {
|
||||
double containerHeight = 92.0;
|
||||
double imageWidth = 156.0;
|
||||
return new Container(height: containerHeight, child: new Image.asset(logo_png, width: imageWidth));
|
||||
return new Container(height: containerHeight, child: new Image.asset(Resources.getLogo(app), width: imageWidth));
|
||||
}
|
||||
|
||||
/// Возвращает текстовое поле, с однострочным пояснением над ним.
|
||||
|
||||
Reference in New Issue
Block a user