Skip to content

Commit

Permalink
refactor: use switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Sep 4, 2023
1 parent 90eedd0 commit cf406fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 38 deletions.
21 changes: 8 additions & 13 deletions mobile/lib/features/trade/order_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ class OrderListItem extends StatelessWidget {
formatter.maximumFractionDigits = 2;

const double iconSize = 18;
Icon statusIcon = () {
switch (order.state) {
case OrderState.open:
return const Icon(
Icons.pending,
size: iconSize,
);
case OrderState.filled:
return const Icon(Icons.check_circle, color: Colors.green, size: iconSize);
case OrderState.failed:
return const Icon(Icons.error, color: Colors.red, size: iconSize);
}
}();
Icon statusIcon = switch (order.state) {
OrderState.open => const Icon(
Icons.pending,
size: iconSize,
),
OrderState.filled => const Icon(Icons.check_circle, color: Colors.green, size: iconSize),
OrderState.failed => const Icon(Icons.error, color: Colors.red, size: iconSize),
};

return Card(
child: ListTile(
Expand Down
38 changes: 13 additions & 25 deletions mobile/lib/features/wallet/wallet_history_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,15 @@ abstract class WalletHistoryItem extends StatelessWidget {
String title = getTitle();
String onOrOff = isOnChain() ? "on-chain" : "off-chain";

String sign = () {
switch (data.flow) {
case PaymentFlow.inbound:
return "+";
case PaymentFlow.outbound:
return "-";
}
}();

Color color = () {
switch (data.flow) {
case PaymentFlow.inbound:
return Colors.green.shade600;
case PaymentFlow.outbound:
return Colors.red.shade600;
}
}();
String sign = switch (data.flow) {
PaymentFlow.inbound => "+",
PaymentFlow.outbound => "-",
};

Color color = switch (data.flow) {
PaymentFlow.inbound => Colors.green.shade600,
PaymentFlow.outbound => Colors.red.shade600,
};

var amountFormatter = NumberFormat.compact(locale: "en_UK");

Expand Down Expand Up @@ -117,14 +109,10 @@ abstract class WalletHistoryItem extends StatelessWidget {
}

Widget showItemDetails(String title, BuildContext context) {
int directionMultiplier = () {
switch (data.flow) {
case PaymentFlow.inbound:
return 1;
case PaymentFlow.outbound:
return -1;
}
}();
int directionMultiplier = switch (data.flow) {
PaymentFlow.inbound => 1,
PaymentFlow.outbound => -1,
};

return AlertDialog(
title: Text(title),
Expand Down

0 comments on commit cf406fe

Please sign in to comment.