Рефакторинг

This commit is contained in:
kifio
2017-07-20 08:44:11 +03:00
parent bb45d252f1
commit 42de9b8f1e
2 changed files with 15 additions and 21 deletions

View File

@@ -21,9 +21,10 @@ 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';
// Colors
const int primaryColor = 0xffeb0004;
// HttpClient
final httpClient = createHttpClient();
void main() {

View File

@@ -12,7 +12,6 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
String _merchantID = "";
String _posID = "";
@override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
@@ -32,41 +31,36 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
Widget _getScreen(BuildContext context) {
return new Center(child: new Column(children: <Widget>[
_getLogo(),
_getDecoratedInputField(merchantIDHint, 0.0),
_getDecoratedInputField(posIDHint, 36.0),
_getDecoratedInputField(),
_getButton(context)
]));
}
Container _getLogo() {
return new Container(height: 192.0,
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
}
Container _getDecoratedInputField(String hint, double topPadding) {
Container _getDecoratedInputField() {
return new Container(
padding: new EdgeInsets.only(left: 28.0, right: 28.0, top: topPadding),
padding: new EdgeInsets.only(left: 28.0, right: 28.0),
child: new Container(height: 48.0,
padding: new EdgeInsets.only(left: 16.0, right: 16.0),
decoration: _getDecoraionForInputField(),
child: _getInputField(hint))) ;
child: _getInputField())) ;
}
TextField _getInputField(String hint) {
return new TextField(decoration: new InputDecoration(hintText: hint,
TextField _getInputField() {
return new TextField(decoration: new InputDecoration(hintText: merchantIDHint,
hideDivider: true,
hintStyle: new TextStyle(color: const Color(0xffa5a5a5),
fontSize: 16.0)), onChanged: (text) => _handleUserInput(hint, text));
fontSize: 16.0)), onChanged: (text) => _handleUserInput(text));
}
void _handleUserInput(String hint, String text) {
void _handleUserInput(String text) {
if (text.length > 0) {
setState(() {
if (hint == merchantIDHint)
_merchantID = text;
else if (hint == posIDHint)
_posID = text;
_merchantID = text;
});
}
}
@@ -83,15 +77,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
child: new Container(height: 64.0, padding: new EdgeInsets.all(8.0),
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
style: new TextStyle(color: Colors.white)),
onPressed: _isFieldsAreFilled() ? () => _registerShop(context, _merchantID) : null,
onPressed: _isValidMerchantID() ? () => _registerShop(context, _merchantID) : null,
disabledColor: const Color(0xffbfbfbf),
color: const Color(0xff3078c0))));
color: primaryColor)));
}
_isFieldsAreFilled() {
_isValidMerchantID() {
print(_merchantID.length);
print(_posID.length);
return _merchantID.length == 5 && _posID.length > 0;
return _merchantID.length == 5;
}
void _registerShop(BuildContext context, String merchantShop) {