cake_wallet/lib/src/screens/dashboard/wallet_menu.dart

98 lines
2.9 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart';
import 'package:provider/provider.dart';
import 'package:cake_wallet/generated/i18n.dart';
2020-01-08 12:26:34 +00:00
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
2020-01-04 19:31:52 +00:00
class WalletMenu {
2020-01-08 12:26:34 +00:00
WalletMenu(this.context);
2020-01-04 19:31:52 +00:00
final List<String> items = [
S.current.reconnect,
S.current.wallets,
S.current.nodes,
2020-01-04 19:31:52 +00:00
S.current.show_seed,
S.current.show_keys,
S.current.address_book_menu,
S.current.settings_title
];
final List<Image> images = [
Image.asset('assets/images/reconnect.png'),
Image.asset('assets/images/wallet.png'),
Image.asset('assets/images/nodes.png'),
Image.asset('assets/images/eye.png'),
Image.asset('assets/images/key.png'),
Image.asset('assets/images/open_book.png'),
Image.asset('assets/images/settings.png'),
2020-01-04 19:31:52 +00:00
];
2020-01-08 12:26:34 +00:00
final BuildContext context;
2020-01-04 19:31:52 +00:00
void action(int index) {
switch (index) {
case 0:
_presentReconnectAlert(context);
break;
case 1:
Navigator.of(context).pushNamed(Routes.walletList);
2020-01-04 19:31:52 +00:00
break;
case 2:
// FIXME: apply Nodes
2020-01-04 19:31:52 +00:00
break;
case 3:
Navigator.of(context).pushNamed(Routes.auth,
2020-01-08 12:26:34 +00:00
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) =>
2020-01-04 19:31:52 +00:00
isAuthenticatedSuccessfully
? Navigator.of(auth.context).popAndPushNamed(Routes.seed)
: null);
break;
case 4:
Navigator.of(context).pushNamed(Routes.auth,
2020-01-08 12:26:34 +00:00
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) =>
2020-01-04 19:31:52 +00:00
isAuthenticatedSuccessfully
? Navigator.of(auth.context)
.popAndPushNamed(Routes.showKeys)
: null);
break;
case 5:
Navigator.of(context).pushNamed(Routes.addressBook);
2020-01-04 19:31:52 +00:00
break;
case 6:
Navigator.of(context).pushNamed(Routes.settings);
2020-01-04 19:31:52 +00:00
break;
default:
break;
}
}
2020-01-08 12:26:34 +00:00
Future<void> _presentReconnectAlert(BuildContext context) async {
2020-01-04 19:31:52 +00:00
final walletStore = Provider.of<WalletStore>(context);
2020-01-08 12:26:34 +00:00
await showDialog<void>(
2020-01-04 19:31:52 +00:00
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(
S.of(context).reconnection,
textAlign: TextAlign.center,
),
content: Text(S.of(context).reconnect_alert_text),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(S.of(context).cancel)),
FlatButton(
onPressed: () {
walletStore.reconnect();
Navigator.of(context).pop();
},
child: Text(S.of(context).ok))
],
);
});
}
}