I’m encountering a TypeError
with the message:
Type '(Job) => ListTile' is not a subtype of type '(dynamic) => Widget'
in my Flutter app when trying to build a widget by passing a callback. The callback type is defined as:
final Widget Function(T) listItemBuilder;
in a class:
class ListPageBuilder<T extends Model> extends StatefulWidget
In the calling code, I instantiated ListPageBuilder
with:
ListPageBuilder(
listItemBuilder: (Job item) {
return ListTile(
key: Key(item.pk!),
title: Text(item.title),
subtitle: Text(item.description),
);
},
);
where Job
inherits from Model
. I expected this to work since Job
is a subclass of Model
, and ListTile
is a Widget
.
How can I resolve this issue?
1