| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:cake_wallet/utils/show_pop_up.dart'; |
| 3 | import 'package:cake_wallet/src/widgets/picker.dart'; |
| 4 | import 'package:cake_wallet/src/widgets/standard_list.dart'; |
| 5 | |
| 6 | class SettingsPickerCell<ItemType> extends StandardListRow { |
| 7 | SettingsPickerCell({ |
| 8 | required String title, |
| 9 | required this.selectedItem, |
| 10 | required this.items, |
| 11 | this.displayItem, |
| 12 | this.images, |
| 13 | this.searchHintText, |
| 14 | this.isGridView = false, |
| 15 | this.matchingCriteria, |
| 16 | this.onItemSelected, |
| 17 | Key? key, |
| 18 | }) : super( |
| 19 | title: title, |
| 20 | isSelected: false, |
| 21 | key: key, |
| 22 | onTap: (BuildContext context) async { |
| 23 | final selectedAtIndex = items.indexOf(selectedItem); |
| 24 | |
| 25 | await showPopUp<void>( |
| 26 | context: context, |
| 27 | builder: (_) => Picker( |
| 28 | items: items, |
| 29 | displayItem: displayItem, |
| 30 | selectedAtIndex: selectedAtIndex, |
| 31 | mainAxisAlignment: MainAxisAlignment.start, |
| 32 | onItemSelected: (ItemType item) => onItemSelected?.call(item), |
| 33 | images: images ?? const <Image>[], |
| 34 | isSeparated: false, |
| 35 | hintText: searchHintText, |
| 36 | isGridView: isGridView, |
| 37 | matchingCriteria: matchingCriteria, |
| 38 | ), |
| 39 | ); |
| 40 | }, |
| 41 | ); |
| 42 | |
| 43 | final ItemType selectedItem; |
| 44 | final List<ItemType> items; |
| 45 | final void Function(ItemType item)? onItemSelected; |
| 46 | final String Function(ItemType item)? displayItem; |
| 47 | final List<Image>? images; |
| 48 | final String? searchHintText; |
| 49 | final bool isGridView; |
| 50 | final bool Function(ItemType, String)? matchingCriteria; |
| 51 | |
| 52 | @override |
| 53 | Widget buildTrailing(BuildContext context) { |
| 54 | return Text( |
| 55 | displayItem?.call(selectedItem) ?? selectedItem.toString(), |
| 56 | textAlign: TextAlign.right, |
| 57 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 58 | fontWeight: FontWeight.w600, |
| 59 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 60 | ), |
| 61 | ); |
| 62 | } |
| 63 | } |