aman-kassa-flutter/lib/views/settings/settings_view.dart

96 lines
3.1 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
import 'package:aman_kassa_flutter/redux/state/setting_state.dart';
import 'package:aman_kassa_flutter/redux/store.dart';
import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:aman_kassa_flutter/shared/ui_helpers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SettingView extends StatefulWidget {
SettingView();
@override
_SettingViewState createState() => _SettingViewState();
}
class _SettingViewState extends State<SettingView> {
TextEditingController _pinController;
final DialogService _dialogService = locator<DialogService>();
@override
void initState() {
super.initState();
SettingState state = Redux.store.state.settingState;
_pinController = new TextEditingController(text: state.pinCode);
}
@override
void dispose() {
_pinController.dispose();
super.dispose();
}
void _setPinCode(BuildContext _context) async {
FocusScope.of(_context).unfocus();
var value = _pinController.text;
if(value.isNotEmpty && value.length !=4){
_dialogService.showDialog(description: 'Необходимо указать 4-х значный числовой код');
} else {
await Redux.store.dispatch(changePinCodeFromSetting(_pinController.text));
_dialogService.showDialog(description: 'Данные успешно сохранены');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Настройка приложения'),
),
body: SingleChildScrollView(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 14.0),
child: Column(
children: <Widget>[
verticalSpaceTiny,
Text(
'Для блокировки приложения пин-кодом, укажите 4-х значный числовой код',
style: TextStyle(fontSize: 15.0),
textAlign: TextAlign.center,
),
verticalSpaceTiny,
TextField(
controller: _pinController,
maxLength: 4,
obscureText: true,
decoration: InputDecoration(
labelText: 'Пин-код', hintText: "Укажите пин-код"),
keyboardType: TextInputType.number,
),
verticalSpaceMedium,
RaisedButton(
onPressed: () => this._setPinCode(context),
child: Text(
'Cохранить настройки',
style: TextStyle(color: whiteColor, fontSize: 20.0),
),
color: primaryColor,
padding:
const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20.0),
),
],
),
),
),
);
}
}