Локализация платформонезависимой части приложения

This commit is contained in:
Ivan Murashov
2017-09-04 18:57:30 +03:00
parent 3c494347dc
commit 6e8269b4df
19 changed files with 176 additions and 133 deletions

View File

@@ -0,0 +1,112 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
import 'package:checker/common.dart';
import 'package:checker/consts.dart';
import 'package:checker/network.dart';
import 'package:checker/base_state.dart';
import 'package:checker/strings.dart';
class FinishRegistrationScreen extends StatefulWidget {
@override State createState() => new _RegistrationScreenState();
}
class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
bool _tokenActive = false;
String _merchantID = '';
_RegistrationScreenState() {
if (textFieldValue == "") {
getSavedMerchantID();
}
}
@override String getTitle() {
return Strings.of(context).registration();
}
@override getHint() {
return Strings.of(context).idStore();
}
@override Widget getScreenContent() {
return new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getDecoratedTextWidget(),
getMessage(),
buildRaisedButton(context, _tokenActive
? Strings.of(context).completeRegistration()
: Strings.of(context).refreshActivationStatus(), () => handleTap())
]);
}
// Если токен активирован, то открывается экран со сканером,
// Если нет, то отправляется запрос на проверку статуса токена.
handleTap() async {
if (_tokenActive) {
startScanner(context);
} else {
if (await platform.invokeMethod('isOnline')) {
checkTokenStatus(token).then((response) {
print(response.body);
Map parsedMap = JSON.decode(response.body);
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
setState(() {
_tokenActive = parsedMap['active'];
});
}).catchError((error) {
print(error.toString());
return false;
});
}
}
}
@override Widget getTextWidget() {
return new Row(children: <Widget>[new Text(_merchantID != null ? _merchantID : '', style: new TextStyle(color: Colors.black, fontSize: 16.0))]);
}
/// Достаем сохраненный в SharedPreferences merchantID.
getSavedMerchantID() {
platform.invokeMethod('getMerchantID').then((result) {
setState(() {
_merchantID = result;
print('merchanID: ${_merchantID}');
});
});
}
/// Метод возвращает контейнер с текстом сообщения и бэкграундом.
getMessage() {
return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecoraionForMessageField(),
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
padding: new EdgeInsets.only(bottom: 22.0, left: 14.0, right: 14.0),
child: new Center(child: getMessageTextWidget()));
}
/// Метод возвращает виджет с текстом сообщения, всеми его привязками и стилями.
getMessageTextWidget() {
return new Text(getMessageString(), textAlign: TextAlign.center,
style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0,
color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor));
}
/// Получаем текст сообщения, в зависимости от статуса активации.
getMessageString() {
return _tokenActive
? Strings.of(context).completeRegistration()
: Strings.of(context).refreshActivationStatus();
}
/// Фоновое изображение для сообщения.
Decoration _getDecoraionForMessageField() {
return new BoxDecoration(image: new DecorationImage(
image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png), fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
}
}