logout, индикатор загрузки на экране регистрации

This commit is contained in:
kifio
2017-07-21 08:40:10 +03:00
parent 0a397f675f
commit c9dba5bb08
10 changed files with 123 additions and 101 deletions

View File

@@ -51,7 +51,7 @@ void checkToken(BuildContext context, Callback callback) {
callback.call(context);
} else {
// Запускается экран сканера, токен кассы активирован, с его помощью можно делать запросы к pos-api.
startScanner();
startScanner(context);
}
}).catchError((error) {
@@ -61,11 +61,24 @@ void checkToken(BuildContext context, Callback callback) {
/// Запуск спецефичной для каждой платформы части приложения - сканера.
/// Может производиться с нескольких экранов (splash, finish_registration).
startScanner() async{
startScanner(BuildContext context) async{
const platform = const MethodChannel('com.dinect.checker/instance_id');
platform.setMethodCallHandler((MethodCall call) async {
logout();
print(call.method);
// dynamic arguments = call.arguments;
// handle call then
return result;
// or
// throw new PlatformException(errorCode, anErrorMessage, someDetails);
});
await platform.invokeMethod('startScanner');
}
logout() {
pushRute(_context, new RegistrationScreen());
}
/// Навигация по приложению.
/// widget - следующий экран приложения.
pushRoute(BuildContext context, Widget widget) {
@@ -73,11 +86,16 @@ pushRoute(BuildContext context, Widget widget) {
builder: (BuildContext context) {
return widget;
}));
}
}
class Checker extends StatelessWidget {
@override Widget build(BuildContext context) {
return new MaterialApp(title: "DemoApp", home: new SplashScreen());
return new MaterialApp(title: "DemoApp",
home: new SplashScreen(),
theme: new ThemeData(
primaryColor: primaryColor,
accentColor: primaryColor
));
}
}
@@ -87,9 +105,6 @@ abstract class BaseState<T> extends State<StatefulWidget> {
}
void logout() {
}
}
abstract class Callback {

View File

@@ -12,6 +12,7 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
String _merchantID = "";
bool _loading = false;
@override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
@@ -19,16 +20,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
AppBar _getAppBar() {
return new AppBar(title: new Text("Регистрация"),
backgroundColor: primaryColor, actions: <Widget>[
new IconButton(
icon: new Icon(Icons.help_outline),
tooltip: 'Air it',
onPressed: faq,
)
]);
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: faq)]);
}
Widget _getScreen(BuildContext context) {
return new Stack(children: <Widget>[_getScreenContent(), _getProgressIndicator()]);
}
Widget _getScreenContent() {
return new Container(height: 332.0,
child: new ListView(reverse: true, children: <Widget>[
new Center(child: new Column(children: <Widget>[
@@ -38,6 +37,10 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
].reversed.toList()));
}
Widget _getProgressIndicator() {
return new Center(child: _loading ? new CircularProgressIndicator() : null);
}
Widget _getLogo() {
return new Container(height: 192.0, width: 156.0,
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
@@ -56,14 +59,6 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
onChanged: (text) => _handleUserInput(text));
}
void _handleUserInput(String text) {
if (text.length > 0) {
setState(() {
_merchantID = text;
});
}
}
Decoration _getDecoraionForInputField() {
return new BoxDecoration(color: Colors.white,
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0,),
@@ -71,19 +66,35 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
}
Widget _getButton(BuildContext context) {
return new Container(margin: new EdgeInsets.only(top: 36.0), height: 42.0, padding: new EdgeInsets.only(left: 40.0, right: 40.0),
return new Container(margin: new EdgeInsets.only(top: 36.0), height: 42.0,
padding: new EdgeInsets.only(left: 40.0, right: 40.0),
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
style: new TextStyle(color: Colors.white)),
onPressed: _isValidMerchantID() ? () => _registerShop(context, _merchantID) : null,
color: primaryColor));
}
bool _isValidMerchantID() {
Widget _getCircularProgressIndicator() {
return new Center(child: new CircularProgressIndicator());
}
_isValidMerchantID() {
return _merchantID.length == 5;
}
void _registerShop(BuildContext context, String merchantShop) {
_register(context, merchantShop);
_handleUserInput(String text) {
if (text.length > 0) {
setState(() {
_merchantID = text;
});
}
}
_registerShop(BuildContext context, String merchantShop) {
setState(() {
loading = true;
_register(context, merchantShop);
});
}
_register(BuildContext context, String merchantShop) async {
@@ -113,6 +124,9 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
platform.invokeMethod('saveToken', {'token' : token}).then((value) {
print(value.toString());
});
setState(() {
loading = false;
});
pushRoute(context, new FinishRegistrationScreen());
}).catchError((error) {
print(error.toString());

View File

@@ -27,11 +27,12 @@ class SplashScreen extends StatelessWidget {
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
if (token == null) {
pushRoute(context, new RegistrationScreen());
} else {
checkToken(context, new CheckTokenCallback());
}
// if (token == null) {
// pushRoute(context, new RegistrationScreen());
// } else {
// checkToken(context, new CheckTokenCallback());
// }
startScanner(context);
}
}
@@ -41,6 +42,7 @@ class CheckTokenCallback extends Callback {
/// Запускается экран ожидания активации токена.
/// В реальности токен активируется в админке вручную,
/// на тестовом сервере токен активируется через несколько минут после создания.
call(BuildContext context) {
pushRoute(context, new FinishRegistrationScreen());
}