Fix Generic Type being enforced to extend Object

This commit is contained in:
OmarHatem 2022-12-16 14:33:33 +02:00
parent 3f7889dac0
commit 6148b91c8a
2 changed files with 5 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/picker.dart';
import 'package:cake_wallet/src/widgets/standard_list.dart';
class SettingsPickerCell<ItemType extends Object> extends StandardListRow {
class SettingsPickerCell<ItemType> extends StandardListRow {
SettingsPickerCell(
{required String title,
required this.selectedItem,

View file

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/alert_background.dart';
import 'package:cake_wallet/src/widgets/alert_close_button.dart';
class Picker<Item extends Object> extends StatefulWidget {
class Picker<Item> extends StatefulWidget {
Picker({
required this.selectedAtIndex,
required this.items,
@ -39,7 +39,7 @@ class Picker<Item extends Object> extends StatefulWidget {
_PickerState<Item> createState() => _PickerState<Item>(items, images, onItemSelected);
}
class _PickerState<Item> extends State<Picker> {
class _PickerState<Item> extends State<Picker<Item>> {
_PickerState(this.items, this.images, this.onItemSelected);
final Function(Item) onItemSelected;
@ -59,7 +59,7 @@ class _PickerState<Item> extends State<Picker> {
images = [];
for (int i=0;i<widget.items.length;i++) {
if (widget.matchingCriteria?.call(widget.items[i], searchController.text) ?? true) {
items.add(widget.items[i] as Item);
items.add(widget.items[i]);
images.add(widget.images[i]);
}
}
@ -238,8 +238,7 @@ class _PickerState<Item> extends State<Picker> {
child: Padding(
padding: EdgeInsets.only(left: image != null ? 12 : 0),
child: Text(
// What a hack (item as) ?
widget.displayItem?.call(item as Object) ?? item.toString(),
widget.displayItem?.call(item) ?? item.toString(),
style: TextStyle(
fontSize: 14,
fontFamily: 'Lato',