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

110 lines
3.6 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';
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 => 'Account';
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);
return Form(
key: _formKey,
child: Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Expanded(
child: Center(
child: TextFormField(
decoration: InputDecoration(
hintStyle: TextStyle(color: Theme.of(context).hintColor),
hintText: S.of(context).account,
focusedBorder: UnderlineInputBorder(
2020-01-08 12:26:34 +00:00
borderSide:
BorderSide(color: Palette.cakeGreen, width: 2.0)),
2020-01-04 19:31:52 +00:00
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).focusColor, width: 1.0))),
controller: _textController,
validator: (value) {
accountListStore.validateAccountName(value);
return accountListStore.errorMessage;
},
),
)),
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 ? 'Rename' : S.of(context).add,
color: Theme.of(context)
.primaryTextTheme
.button
.backgroundColor,
textColor: Theme.of(context).primaryTextTheme.button.color,
2020-01-04 19:31:52 +00:00
isLoading: accountListStore.isAccountCreating,
))
],
),
),
);
}
}