Skip to content

Commit

Permalink
Refactor modal bottom sheet list
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong committed Feb 6, 2024
1 parent a3b7414 commit 54bc3ae
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
3 changes: 2 additions & 1 deletion frontend/lib/features/deposit/deposit_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class DepositPage extends HookWidget {
(value) => selectedCurrencyItem.value =
supportedCurrencyList.firstWhere(
(element) => element['label'] == value),
supportedCurrencyList);
supportedCurrencyList,
selectedCurrencyItem.value['label'].toString());
},
),
const SizedBox(height: Grid.xl),
Expand Down
3 changes: 2 additions & 1 deletion frontend/lib/features/withdraw/withdraw_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class WithdrawPage extends HookWidget {
(value) => selectedCurrencyItem.value =
supportedCurrencyList.firstWhere(
(element) => element['label'] == value),
supportedCurrencyList);
supportedCurrencyList,
selectedCurrencyItem.value['label'].toString());
},
),
const SizedBox(height: Grid.xl),
Expand Down
59 changes: 33 additions & 26 deletions frontend/lib/shared/currency_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,46 @@ class CurrencyModal {
static Future<dynamic> showCurrencyModal(
BuildContext context,
Function(String) onPressed,
List<Map<String, Object>> supportedCurrencyList) {
List<Map<String, Object>> supportedCurrencyList,
String selectedCurrency) {
return showModalBottomSheet(
useSafeArea: true,
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: ListView(
children: supportedCurrencyList.map((Map<String, Object> map) {
return SafeArea(
child: SizedBox(
height: supportedCurrencyList.length * 80,
child: Column(children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: Grid.xs),
child: Text(
'Select currency',
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
)),
Expanded(
child: ListView(
children:
supportedCurrencyList.map((Map<String, Object> map) {
IconData icon = map['icon'] as IconData;
String label = map['label'].toString();
return TextButton(
onPressed: () {
onPressed(label);
Navigator.pop(context);
},
child: Row(children: [
Icon(icon),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: Grid.side, vertical: Grid.xs),
child: Text(label,
style: Theme.of(context).textTheme.titleMedium),
),
)
]));
}).toList(),
),
),
);
return (ListTile(
onTap: () {
onPressed(label);
Navigator.pop(context);
},
leading: Icon(icon),
title: Text(label,
style: Theme.of(context).textTheme.titleMedium),
trailing: (selectedCurrency == label)
? const Icon(Icons.check)
: null,
));
}).toList()),
)
]),
));
});
}
}
13 changes: 13 additions & 0 deletions frontend/test/features/deposit/deposit_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,18 @@ void main() {
await tester.pump();
}
});

testWidgets(
'should show the currency list on tap of the currency converter dropdown toggle',
(tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const DepositPage()),
);

await tester.tap(find.byIcon(Icons.keyboard_arrow_down));
await tester.pump();

expect(find.byType(ListView), findsOneWidget);
});
});
}
13 changes: 13 additions & 0 deletions frontend/test/features/withdraw/withdraw_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,18 @@ void main() {
await tester.pump();
}
});

testWidgets(
'should show the currency list on tap of the currency converter dropdown toggle',
(tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const WithdrawPage()),
);

await tester.tap(find.byIcon(Icons.keyboard_arrow_down));
await tester.pump();

expect(find.byType(ListView), findsOneWidget);
});
});
}

0 comments on commit 54bc3ae

Please sign in to comment.