Продолжаю разбираться с локализацией
This commit is contained in:
90
lib/registration.dart
Normal file
90
lib/registration.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:checker/finish_registration.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
|
||||
|
||||
import 'package:checker/common.dart';
|
||||
import 'package:checker/network.dart';
|
||||
import 'package:checker/base_state.dart';
|
||||
import 'package:checker/strings.dart';
|
||||
|
||||
/// Экран регистрации магазина и кассы.
|
||||
class RegistrationScreen extends StatefulWidget {
|
||||
@override State createState() => new _RegistrationScreenState();
|
||||
}
|
||||
|
||||
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
|
||||
@override String getTitle(BuildContext ctx) {
|
||||
return "registration";
|
||||
}
|
||||
|
||||
@override getHint(BuildContext ctx) {
|
||||
return "idStore()";
|
||||
}
|
||||
|
||||
// Список виджетов, автоматически прокручиваемый вверх при открытии клавиатуры.
|
||||
@override Widget getScreenContent(BuildContext ctx) {
|
||||
print(new Strings().registration());
|
||||
return new Container(
|
||||
child: new ListView(children: <Widget>[
|
||||
new Column(children: <Widget>[
|
||||
getLogo(),
|
||||
getHintLabel(ctx),
|
||||
getInputField(ctx),
|
||||
getButton(ctx)])
|
||||
]));
|
||||
}
|
||||
|
||||
/// Возвращает кнопку регистрации.
|
||||
getButton(BuildContext ctx) {
|
||||
return new Container(margin: new EdgeInsets.only(top: 36.0), child:
|
||||
buildRaisedButton(ctx, "signUp()", getOnPressed(ctx)));
|
||||
}
|
||||
|
||||
// Возвращает обработчик нажатий на кнопку регистрации.
|
||||
getOnPressed(BuildContext ctx) {
|
||||
return _isValidMerchantID() && !loading ? () => _registerShop(ctx) : null;
|
||||
}
|
||||
|
||||
/// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов.
|
||||
_isValidMerchantID() {
|
||||
print("${textFieldValue.length}");
|
||||
return textFieldValue.length > 0 && textFieldValue.length < 25;
|
||||
}
|
||||
|
||||
/// Показать progressBar, запросить токен.
|
||||
_registerShop(BuildContext ctx) {
|
||||
setState(() {
|
||||
loading = true;
|
||||
_register(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
/// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена.
|
||||
_register(BuildContext ctx) async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
createToken(textFieldValue, await platform.invokeMethod('getPosID')).then((response) {
|
||||
|
||||
setState(() {
|
||||
error = null;
|
||||
loading = false;
|
||||
});
|
||||
|
||||
print(response.body);
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
if (response.statusCode == 201) {
|
||||
token = parsedMap['token'];
|
||||
platform.invokeMethod('saveToken', {'token' : token});
|
||||
platform.invokeMethod('saveMerchantID', {'merchantID' : textFieldValue});
|
||||
pushRoute(ctx, new FinishRegistrationScreen());
|
||||
} else {
|
||||
setState(() {
|
||||
error = parsedMap['errors'][0];
|
||||
});
|
||||
}
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user