Вынес дублирующийся код в базовый класс

This commit is contained in:
kifio
2017-07-23 20:35:18 +04:00
parent 8cf5d4b028
commit 3f7dc05d9e
8 changed files with 595 additions and 186 deletions

87
lib/base_state.dart Normal file
View File

@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'dart:async';
import 'main.dart';
abstract class BaseState<T> extends State<T> {
bool loading = false;
String error = null;
String textFieldValue = "";
AppBar getAppBar() {
return new AppBar(title: new Text(getTitle(), style: new TextStyle(fontSize: 18.0)),
backgroundColor: primaryColor, actions: getMenuButtons());
}
String getTitle();
String getHint();
getMenuButtons();
/// Метод возвращает контейнер с отступами, который содержит картинку с логотипом.
getLogo() {
double containerHeight = 92.0;
double imageWidth = 156.0;
return new Container(height: containerHeight, child: new Image.asset(logo_png, width: imageWidth));
}
getHintLabel() {
double horizontalMargin = 8.0;
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(getHintText(), overflow: TextOverflow.ellipsis, textAlign: TextAlign.left,
style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : primaryColor, fontSize: 14.0))]));
}
getHintText() {
if (textFieldValue.length == 0 && error == null) {
return ' ';
} else if (error != null) {
return error;
} else {
return getHint();
}
}
/// Метод возвращает контейнер с установленными отступами, в котором размещен TextField обернутый в BoxDecoration.
getDecoratedTextWidget() {
return new Container(margin: new EdgeInsets.only(left: verticalMargin, right: verticalMargin),
padding: getPaddingForTextWidget(),
decoration: getDecoraionForTextWidget(),
child: getTextWidget());
}
getPaddingForTextWidget() {
const double verticalPadding = 12.0;
const double horizontalPadding = 16.0;
return new EdgeInsets.only(top: verticalPadding,
bottom: verticalPadding,
left: horizontalPadding,
right: horizontalPadding);
}
/// Метод возвращает BoxDecoration для _getDecoratedInputField
getDecoraionForTextWidget() {
return new BoxDecoration(color: textFieldBackground,
border: new Border.all(color: textBorderColor, width: 1.0,),
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
}
Widget getTextWidget() {
return new TextField(keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(hintText: getHint(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
onChanged: (text) => _handleUserInput(text));
}
/// Индикация ...
Widget getProgressIndicator() {
return new Center(child: loading ? new CircularProgressIndicator() : null);
}
}