zwallet/lib/account_manager.dart

103 lines
3.5 KiB
Dart
Raw Normal View History

2021-06-26 07:30:12 -07:00
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:warp/main.dart';
import 'package:warp/store.dart';
2021-07-07 21:22:54 -07:00
import 'about.dart';
2021-06-26 07:30:12 -07:00
class AccountManagerPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => AccountManagerState();
}
class AccountManagerState extends State<AccountManagerPage> {
@override
initState() {
super.initState();
2021-07-07 21:22:54 -07:00
Future.microtask(accountManager.refresh);
showAboutOnce(this.context);
2021-06-26 07:30:12 -07:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Accounts')),
body: Observer(
builder: (context) => Stack(children: [
accountManager.accounts.isEmpty
? Center(
child: Text("No account",
style: Theme.of(context).textTheme.headline5))
: ListView(
children: accountManager.accounts
.asMap()
.entries
.map((a) => Card(
child: Dismissible(
key: Key(a.value.name),
child: ListTile(
title: Text(a.value.name,
style: Theme.of(context)
.textTheme
.headline5),
trailing:
Text("${a.value.balance / ZECUNIT}"),
onTap: () {
_selectAccount(a.value);
},
),
confirmDismiss: _onAccountDelete,
onDismissed: (direction) =>
_onDismissed(a.key, a.value.id),
)))
.toList()),
])),
floatingActionButton: FloatingActionButton(
onPressed: _onRestore, child: Icon(Icons.add)));
}
Future<bool> _onAccountDelete(DismissDirection _direction) async {
2021-07-07 08:40:05 -07:00
if (accountManager.accounts.length == 1) return false;
2021-06-26 07:30:12 -07:00
final confirm = showDialog<bool>(
context: this.context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text('Seed'),
2021-07-07 08:40:05 -07:00
content: Text('Are you SURE you want to DELETE this account? You MUST have a BACKUP to recover it. This operation is NOT reversible.'),
2021-06-26 07:30:12 -07:00
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(this.context).pop(false);
},
),
TextButton(
2021-07-07 08:40:05 -07:00
child: Text('DELETE'),
2021-06-26 07:30:12 -07:00
onPressed: () {
Navigator.of(this.context).pop(true);
},
),
]),
);
return confirm;
}
void _onDismissed(int index, int account) async {
await accountManager.delete(account);
accountManager.refresh();
}
2021-07-09 06:33:39 -07:00
_selectAccount(Account account) async {
await accountManager.setActiveAccount(account);
2021-06-26 07:30:12 -07:00
final navigator = Navigator.of(context);
if (navigator.canPop())
navigator.pop();
else
navigator.pushReplacementNamed('/account');
}
_onRestore() {
Navigator.of(context).pushNamed('/restore');
}
}