This commit is contained in:
M
2020-08-27 19:54:34 +03:00
parent 5eefd6a31b
commit 6aaac93fa8
28 changed files with 364 additions and 143 deletions
@@ -50,10 +50,7 @@ class DashboardPage extends BasePage {
padding: EdgeInsets.all(0),
onPressed: () async {
await showDialog<void>(
builder: (_) => MenuWidget(
name: walletViewModel.name,
subname: walletViewModel.subname,
type: walletViewModel.type),
builder: (_) => MenuWidget(walletViewModel),
context: context);
},
child: menuButton
+7 -7
View File
@@ -6,8 +6,10 @@ import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
// FIXME: terrible design
class WalletMenu {
WalletMenu(this.context);
WalletMenu(this.context, this.reconnect);
final List<String> items = [
S.current.reconnect,
@@ -30,6 +32,7 @@ class WalletMenu {
];
final BuildContext context;
final Future<void> Function() reconnect;
void action(int index) {
switch (index) {
@@ -70,8 +73,6 @@ class WalletMenu {
}
Future<void> _presentReconnectAlert(BuildContext context) async {
final walletStore = Provider.of<WalletStore>(context);
await showDialog<void>(
context: context,
builder: (BuildContext context) {
@@ -80,12 +81,11 @@ class WalletMenu {
alertContent: S.of(context).reconnect_alert_text,
leftButtonText: S.of(context).ok,
rightButtonText: S.of(context).cancel,
actionLeftButton: () {
walletStore.reconnect();
actionLeftButton: () async {
await reconnect?.call();
Navigator.of(context).pop();
},
actionRightButton: () => Navigator.of(context).pop()
);
actionRightButton: () => Navigator.of(context).pop());
});
}
}
@@ -1,14 +1,15 @@
import 'dart:ui';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/screens/dashboard/wallet_menu.dart';
class MenuWidget extends StatefulWidget {
MenuWidget({this.type, this.name, this.subname});
// FIXME: terrible design.
final WalletType type;
final String name;
final String subname;
class MenuWidget extends StatefulWidget {
MenuWidget(this.dashboardViewModel);
final DashboardViewModel dashboardViewModel;
@override
MenuWidgetState createState() => MenuWidgetState();
@@ -65,8 +66,8 @@ class MenuWidgetState extends State<MenuWidget> {
@override
Widget build(BuildContext context) {
final walletMenu = WalletMenu(context);
// final walletStore = Provider.of<WalletStore>(context);
final walletMenu =
WalletMenu(context, () async => widget.dashboardViewModel.reconnect());
final itemCount = walletMenu.items.length;
return Row(
@@ -118,19 +119,20 @@ class MenuWidgetState extends State<MenuWidget> {
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
_iconFor(type: widget.type),
_iconFor(type: widget.dashboardViewModel.type),
SizedBox(width: 16),
Expanded(
child: Container(
height: 40,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: widget.subname != null
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.center,
mainAxisAlignment:
widget.dashboardViewModel.subname != null
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.center,
children: <Widget>[
Text(
widget.name,
widget.dashboardViewModel.name,
style: TextStyle(
color: Theme.of(context)
.primaryTextTheme
@@ -141,9 +143,9 @@ class MenuWidgetState extends State<MenuWidget> {
fontSize: 20,
fontWeight: FontWeight.bold),
),
if (widget.subname != null)
if (widget.dashboardViewModel.subname != null)
Text(
widget.subname,
widget.dashboardViewModel.subname,
style: TextStyle(
color: Theme.of(context)
.primaryTextTheme
+34 -8
View File
@@ -74,15 +74,41 @@ class NodeListPage extends BasePage {
}
final node = nodeListViewModel.nodes[index];
final isSelected = index == 1; // FIXME: hardcoded value.
final nodeListRow = NodeListRow(
title: node.uri,
isSelected: isSelected,
isAlive: node.requestNode(),
onTap: (_) {});
title: node.value.uri,
isSelected: node.isSelected,
isAlive: node.value.requestNode(),
onTap: (_) async {
if (node.isSelected) {
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(
S.of(context).change_current_node(node.value.uri),
textAlign: TextAlign.center,
),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text(S.of(context).cancel)),
FlatButton(
onPressed: () async {
Navigator.of(context).pop();
await nodeListViewModel
.setAsCurrent(node.value);
},
child: Text(S.of(context).change)),
],
);
});
});
final dismissibleRow = Dismissible(
key: Key('${node.key}'),
key: Key('${node.value.key}'),
confirmDismiss: (direction) async {
return await showDialog(
context: context,
@@ -99,7 +125,7 @@ class NodeListPage extends BasePage {
});
},
onDismissed: (direction) async =>
nodeListViewModel.delete(node),
nodeListViewModel.delete(node.value),
direction: DismissDirection.endToStart,
background: Container(
padding: EdgeInsets.only(right: 10.0),
@@ -120,7 +146,7 @@ class NodeListPage extends BasePage {
)),
child: nodeListRow);
return isSelected ? nodeListRow : dismissibleRow;
return node.isSelected ? nodeListRow : dismissibleRow;
},
itemCounter: (int sectionIndex) {
if (sectionIndex == 0) {
@@ -63,14 +63,6 @@ class WalletListBodyState extends State<WalletListBody> {
itemBuilder: (__, index) {
final wallet = widget.walletListViewModel.wallets[index];
final screenWidth = MediaQuery.of(context).size.width;
// String shortAddress = '';
// if (wallet.isCurrent) {
// shortAddress = wallet.address;
// shortAddress = shortAddress.replaceRange(
// 4, shortAddress.length - 4, '...');
// }
final walletMenu = WalletMenu(context, widget.walletListViewModel);
final items =
walletMenu.generateItemsForWalletMenu(wallet.isCurrent);
+1 -1
View File
@@ -109,7 +109,7 @@ class WalletMenu {
try {
auth.changeProcessText(
S.of(context).wallet_list_removing_wallet(wallet.name));
// await _walletListStore.remove(wallet);
await walletListViewModel.remove(wallet);
auth.close();
} catch (e) {
auth.changeProcessText(S