aman-kassa-flutter/lib/views/bank_setting/forte_setting_view.dart

139 lines
4.6 KiB
Dart
Raw 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 'dart:convert';
import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/models/aman_dao.dart';
import 'package:aman_kassa_flutter/core/models/forte/forte_post_session.dart';
import 'package:aman_kassa_flutter/core/models/halyk/halyk_post_session.dart';
import 'package:aman_kassa_flutter/core/services/BankService.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
import 'package:aman_kassa_flutter/redux/actions/bank_actions.dart';
import 'package:aman_kassa_flutter/redux/state/bank_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 ForteSettingView extends StatefulWidget {
ForteSettingView();
@override
_ForteSettingViewState createState() => _ForteSettingViewState();
}
class _ForteSettingViewState extends State<ForteSettingView> {
TextEditingController _emailController;
TextEditingController _passwordController;
final DialogService _dialogService = locator<DialogService>();
String _sessionType;
@override
void initState() {
super.initState();
BankState state = Redux.store.state.bankState;
_emailController = new TextEditingController(text: state.login);
_passwordController = new TextEditingController(text: state.password);
//permissions();
_sessionType = 'Forte';
}
// Future<void> permissions() async {
// try {
// await _bankService.permissions();
// } on PlatformException {
//
// }
// }
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
void _saveData(BuildContext _context) async {
FocusScope.of(_context).unfocus();
await Redux.store.dispatch(saveData(
_emailController.text,
_passwordController.text,
sessionType: _sessionType,
));
_dialogService.showDialog(description: 'Данные сохранены');
}
@override
Widget build(BuildContext context) {
// Получаем состояние
final BankState state = Redux.store.state.bankState;
// Проверяем, активна ли Forte-сессия
if (!(state.login == null || state.login.isEmpty) ||
!(state.password == null || state.password.isEmpty)) {
if (state.sessionType != 'Forte') {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Настройка FortePos'),
),
body: Center(
child: Text(
'У вас подключен терминал Halyk',
style: TextStyle(fontSize: 16.0, color: Colors.grey),
),
),
);
}
}
// Если сессия Forte, отображаем данные
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Настройка FortePos'),
),
body: SingleChildScrollView(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 14.0),
child: Column(
children: <Widget>[
verticalSpaceTiny,
Text(
'Необходимо указать почту и пароль для подключения к системе проведения платежей',
style: TextStyle(fontSize: 15.0),
textAlign: TextAlign.center,
),
verticalSpaceTiny,
TextField(
controller: _emailController,
decoration: InputDecoration(
labelText: 'E-Mail', hintText: "Введите адрес почты"),
keyboardType: TextInputType.emailAddress,
),
TextField(
controller: _passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Пароль', hintText: "Введите пароль"),
),
verticalSpaceMedium,
RaisedButton(
onPressed: () => this._saveData(context),
child: Text(
'Cохранить',
style: TextStyle(color: whiteColor, fontSize: 25.0),
),
color: primaryColor,
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20.0),
),
],
),
),
),
);
}
}