| 1 | import 'package:flutter/foundation.dart'; |
| 2 | import 'package:cake_wallet/view_model/settings/settings_list_item.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | |
| 5 | class PickerListItem<ItemType extends Object> extends SettingsListItem { |
| 6 | PickerListItem( |
| 7 | {required String title, |
| 8 | required this.selectedItem, |
| 9 | required this.items, |
| 10 | this.displayItem, |
| 11 | this.images, |
| 12 | this.searchHintText, |
| 13 | this.isGridView = false, |
| 14 | void Function(ItemType item)? onItemSelected, |
| 15 | bool Function(ItemType item, String searchText)? matchingCriteria}) |
| 16 | : _onItemSelected = onItemSelected, |
| 17 | _matchingCriteria = matchingCriteria, |
| 18 | super(title); |
| 19 | |
| 20 | final ItemType Function() selectedItem; |
| 21 | final List<ItemType> items; |
| 22 | final String Function(ItemType item)? displayItem; |
| 23 | final void Function(ItemType item)? _onItemSelected; |
| 24 | final List<Image>? images; |
| 25 | final String? searchHintText; |
| 26 | final bool isGridView; |
| 27 | final bool Function(ItemType, String)? _matchingCriteria; |
| 28 | |
| 29 | void onItemSelected(dynamic item) { |
| 30 | if (item is ItemType) { |
| 31 | _onItemSelected?.call(item); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | bool matchingCriteria(dynamic item, String searchText) { |
| 36 | if (item is ItemType) { |
| 37 | return _matchingCriteria?.call(item, searchText) ?? false; |
| 38 | } |
| 39 | return true; |
| 40 | } |
| 41 | } |