| 1 | import 'package:cake_wallet/utils/show_pop_up.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | import 'package:cake_wallet/src/widgets/picker.dart'; |
| 4 | import 'package:cake_wallet/src/widgets/standard_list.dart'; |
| 5 | |
| 6 | class SettingsPriorityPickerCell<ItemType> extends StandardListRow { |
| 7 | SettingsPriorityPickerCell({ |
| 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.customValue, |
| 17 | this.maxValue, |
| 18 | this.customItemIndex, |
| 19 | this.onItemSelected, |
| 20 | }) : super( |
| 21 | title: title, |
| 22 | isSelected: false, |
| 23 | onTap: (BuildContext context) async { |
| 24 | var selectedAtIndex = items.indexOf(selectedItem); |
| 25 | double sliderValue = customValue ?? 0.0; |
| 26 | |
| 27 | await showPopUp<void>( |
| 28 | context: context, |
| 29 | builder: (BuildContext context) { |
| 30 | return StatefulBuilder( |
| 31 | builder: (BuildContext context, StateSetter setState) { |
| 32 | return Picker( |
| 33 | items: items, |
| 34 | displayItem: (ItemType item) => displayItem!(item, sliderValue.round()), |
| 35 | selectedAtIndex: selectedAtIndex, |
| 36 | customItemIndex: customItemIndex, |
| 37 | maxValue: maxValue, |
| 38 | headerEnabled: false, |
| 39 | closeOnItemSelected: false, |
| 40 | mainAxisAlignment: MainAxisAlignment.center, |
| 41 | sliderValue: sliderValue, |
| 42 | onSliderChanged: (double newValue) => |
| 43 | setState(() => sliderValue = newValue), |
| 44 | onItemSelected: (ItemType priority) { |
| 45 | setState(() => selectedAtIndex = items.indexOf(priority)); |
| 46 | onItemSelected?.call(priority, sliderValue); |
| 47 | }, |
| 48 | ); |
| 49 | }, |
| 50 | ); |
| 51 | }, |
| 52 | ); |
| 53 | onItemSelected?.call(items[selectedAtIndex], sliderValue); |
| 54 | }); |
| 55 | |
| 56 | final ItemType selectedItem; |
| 57 | final List<ItemType> items; |
| 58 | final void Function(ItemType item, double customValue)? onItemSelected; |
| 59 | final String Function(ItemType item, int value)? displayItem; |
| 60 | final List<Image>? images; |
| 61 | final String? searchHintText; |
| 62 | final bool isGridView; |
| 63 | final bool Function(ItemType, String)? matchingCriteria; |
| 64 | double? customValue; |
| 65 | double? maxValue; |
| 66 | int? customItemIndex; |
| 67 | |
| 68 | @override |
| 69 | Widget buildTrailing(BuildContext context) { |
| 70 | return Text( |
| 71 | displayItem?.call(selectedItem, customValue?.round() ?? 0) ?? selectedItem.toString(), |
| 72 | textAlign: TextAlign.right, |
| 73 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 74 | fontWeight: FontWeight.w500, |
| 75 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 76 | ), |
| 77 | ); |
| 78 | } |
| 79 | } |