|
|
|
@ -10,6 +10,7 @@ import 'package:cake_wallet/src/screens/nodes/widgets/node_list_row.dart';
|
|
|
|
|
import 'package:cake_wallet/src/widgets/standard_list.dart';
|
|
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
|
|
|
|
import 'package:cake_wallet/view_model/node_list/node_list_view_model.dart';
|
|
|
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
|
|
|
|
|
|
|
|
class NodeListPage extends BasePage {
|
|
|
|
|
NodeListPage(this.nodeListViewModel);
|
|
|
|
@ -59,102 +60,104 @@ class NodeListPage extends BasePage {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget body(context) {
|
|
|
|
|
Widget body(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 10),
|
|
|
|
|
child: Observer(
|
|
|
|
|
builder: (_) => SectionStandardList(
|
|
|
|
|
sectionCount: 2,
|
|
|
|
|
context: context,
|
|
|
|
|
itemBuilder: (_, sectionIndex, index) {
|
|
|
|
|
return Observer(builder: (_) {
|
|
|
|
|
if (sectionIndex == 0) {
|
|
|
|
|
return NodeHeaderListRow(
|
|
|
|
|
title: S.of(context).add_new_node,
|
|
|
|
|
onTap: (_) async => await Navigator.of(context)
|
|
|
|
|
.pushNamed(Routes.newNode));
|
|
|
|
|
}
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return nodeListViewModel.nodes.isNotEmpty
|
|
|
|
|
? SectionStandardList(
|
|
|
|
|
sectionCount: 2,
|
|
|
|
|
context: context,
|
|
|
|
|
itemCounter: (int sectionIndex) {
|
|
|
|
|
if (sectionIndex == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final node = nodeListViewModel.nodes[index];
|
|
|
|
|
final isSelected = node.keyIndex ==
|
|
|
|
|
nodeListViewModel.settingsStore.currentNode.keyIndex;
|
|
|
|
|
final nodeListRow = NodeListRow(
|
|
|
|
|
title: node.uri,
|
|
|
|
|
isSelected: isSelected,
|
|
|
|
|
isAlive: node.requestNode(),
|
|
|
|
|
onTap: (_) async {
|
|
|
|
|
if (isSelected) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return nodeListViewModel.nodes.length;
|
|
|
|
|
},
|
|
|
|
|
itemBuilder: (_, sectionIndex, index) {
|
|
|
|
|
if (sectionIndex == 0) {
|
|
|
|
|
return NodeHeaderListRow(
|
|
|
|
|
title: S.of(context).add_new_node,
|
|
|
|
|
onTap: (_) async => await Navigator.of(context)
|
|
|
|
|
.pushNamed(Routes.newNode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await showPopUp<void>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
// FIXME: Add translation.
|
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
|
alertTitle: 'Change current node',
|
|
|
|
|
alertContent:
|
|
|
|
|
S.of(context).change_current_node(node.uri),
|
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
|
rightButtonText: S.of(context).change,
|
|
|
|
|
actionLeftButton: () =>
|
|
|
|
|
Navigator.of(context).pop(),
|
|
|
|
|
actionRightButton: () async {
|
|
|
|
|
await nodeListViewModel.setAsCurrent(node);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
final node = nodeListViewModel.nodes[index];
|
|
|
|
|
final isSelected = node.keyIndex ==
|
|
|
|
|
nodeListViewModel.settingsStore.currentNode.keyIndex;
|
|
|
|
|
final nodeListRow = NodeListRow(
|
|
|
|
|
title: node.uri,
|
|
|
|
|
isSelected: isSelected,
|
|
|
|
|
isAlive: node.requestNode(),
|
|
|
|
|
onTap: (_) async {
|
|
|
|
|
if (isSelected) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final dismissibleRow = Dismissible(
|
|
|
|
|
key: Key('${node.keyIndex}'),
|
|
|
|
|
confirmDismiss: (direction) async {
|
|
|
|
|
return await showPopUp(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
|
alertTitle: S.of(context).remove_node,
|
|
|
|
|
alertContent: S.of(context).remove_node_message,
|
|
|
|
|
rightButtonText: S.of(context).remove,
|
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
|
actionRightButton: () =>
|
|
|
|
|
Navigator.pop(context, true),
|
|
|
|
|
actionLeftButton: () =>
|
|
|
|
|
Navigator.pop(context, false));
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onDismissed: (direction) async =>
|
|
|
|
|
nodeListViewModel.delete(node),
|
|
|
|
|
direction: DismissDirection.endToStart,
|
|
|
|
|
background: Container(
|
|
|
|
|
padding: EdgeInsets.only(right: 10.0),
|
|
|
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
|
|
|
color: Palette.red,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
const Icon(
|
|
|
|
|
CupertinoIcons.delete,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
S.of(context).delete,
|
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
)),
|
|
|
|
|
child: nodeListRow);
|
|
|
|
|
await showPopUp<void>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
// FIXME: Add translation.
|
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
|
alertTitle: 'Change current node',
|
|
|
|
|
alertContent: S
|
|
|
|
|
.of(context)
|
|
|
|
|
.change_current_node(node.uri),
|
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
|
rightButtonText: S.of(context).change,
|
|
|
|
|
actionLeftButton: () =>
|
|
|
|
|
Navigator.of(context).pop(),
|
|
|
|
|
actionRightButton: () async {
|
|
|
|
|
await nodeListViewModel
|
|
|
|
|
.setAsCurrent(node);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return isSelected ? nodeListRow : dismissibleRow;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
itemCounter: (int sectionIndex) {
|
|
|
|
|
if (sectionIndex == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
final dismissibleRow = Slidable(
|
|
|
|
|
key: Key('${node.keyIndex}'),
|
|
|
|
|
actionPane: SlidableDrawerActionPane(),
|
|
|
|
|
child: nodeListRow,
|
|
|
|
|
secondaryActions: <Widget>[
|
|
|
|
|
IconSlideAction(
|
|
|
|
|
caption: S.of(context).delete,
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
icon: CupertinoIcons.delete,
|
|
|
|
|
onTap: () async {
|
|
|
|
|
final confirmed = await showPopUp<bool>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
|
alertTitle:
|
|
|
|
|
S.of(context).remove_node,
|
|
|
|
|
alertContent: S
|
|
|
|
|
.of(context)
|
|
|
|
|
.remove_node_message,
|
|
|
|
|
rightButtonText:
|
|
|
|
|
S.of(context).remove,
|
|
|
|
|
leftButtonText:
|
|
|
|
|
S.of(context).cancel,
|
|
|
|
|
actionRightButton: () =>
|
|
|
|
|
Navigator.pop(context, true),
|
|
|
|
|
actionLeftButton: () =>
|
|
|
|
|
Navigator.pop(context, false));
|
|
|
|
|
}) ??
|
|
|
|
|
false;
|
|
|
|
|
|
|
|
|
|
if (confirmed) {
|
|
|
|
|
await nodeListViewModel.delete(node);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return nodeListViewModel.nodes.length;
|
|
|
|
|
}),
|
|
|
|
|
return isSelected ? nodeListRow : dismissibleRow;
|
|
|
|
|
})
|
|
|
|
|
: Container();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|