cake_wallet/lib/src/screens/accounts/account_page.dart

113 lines
3.5 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:provider/provider.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/stores/account_list/account_list_store.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/domain/monero/account.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
2020-01-04 19:31:52 +00:00
class AccountPage extends BasePage {
2020-01-08 12:26:34 +00:00
AccountPage({this.account});
2020-01-04 19:31:52 +00:00
final Account account;
2020-01-08 12:26:34 +00:00
@override
String get title => S.current.account;
@override
Color get backgroundColor => PaletteDark.historyPanel;
2020-01-04 19:31:52 +00:00
@override
Widget body(BuildContext context) => AccountForm(account);
}
class AccountForm extends StatefulWidget {
AccountForm(this.account);
2020-01-08 12:26:34 +00:00
final Account account;
2020-01-04 19:31:52 +00:00
@override
2020-01-08 12:26:34 +00:00
AccountFormState createState() => AccountFormState();
2020-01-04 19:31:52 +00:00
}
class AccountFormState extends State<AccountForm> {
final _formKey = GlobalKey<FormState>();
final _textController = TextEditingController();
@override
void initState() {
if (widget.account != null) _textController.text = widget.account.label;
super.initState();
}
@override
void dispose() {
_textController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final accountListStore = Provider.of<AccountListStore>(context);
_textController.addListener(() {
if (_textController.text.isNotEmpty) {
accountListStore.setDisabledStatus(false);
} else {
accountListStore.setDisabledStatus(true);
}
});
2020-01-04 19:31:52 +00:00
return Form(
key: _formKey,
child: Container(
color: PaletteDark.historyPanel,
padding: EdgeInsets.all(24.0),
2020-01-04 19:31:52 +00:00
child: Column(
children: <Widget>[
Expanded(
child: Center(
child: BaseTextFormField(
controller: _textController,
2020-01-04 19:31:52 +00:00
hintText: S.of(context).account,
validator: (value) {
accountListStore.validateAccountName(value);
return accountListStore.errorMessage;
},
)
2020-01-04 19:31:52 +00:00
)),
Observer(
builder: (_) => LoadingPrimaryButton(
onPressed: () async {
if (!_formKey.currentState.validate()) {
return;
}
if (widget.account != null) {
await accountListStore.renameAccount(
index: widget.account.id,
label: _textController.text);
} else {
await accountListStore.addAccount(
label: _textController.text);
}
2020-01-08 12:26:34 +00:00
Navigator.of(context).pop(_textController.text);
2020-01-04 19:31:52 +00:00
},
text:
widget.account != null ? S.of(context).rename : S.of(context).add,
color: Colors.green,
textColor: Colors.white,
2020-01-04 19:31:52 +00:00
isLoading: accountListStore.isAccountCreating,
isDisabled: accountListStore.isDisabledStatus,
2020-01-04 19:31:52 +00:00
))
],
),
),
);
}
}