Typing problem in Flutter while getting widget data

I've got a problem with typing in dart. Here is my class. As you can see it gets

   final List<dynamic Function(Row)> colExtractors;
   final List<Row> data;

here is the class:

 class CustomDataTable<Row> extends StatefulWidget {
  final List<String> columns;
  final Function sort;
  final List<dynamic Function(Row)> colExtractors;
  final List<Row> data;
  final Function(Row) route;
      {@required this.columns,
  _CustomDataTableState<Row> createState() => _CustomDataTableState<Row>();

Afterwards, I'm using those data in a method:

   List<DataRow> getTableRows() {
        return (widget.data as List<Row>).map<DataRow>((Row item) {
          return DataRow(
              cells: (widget.colExtractors as List<dynamic Function(Row)>)
                  .map<DataCell>((Function(Row) extractor) {
            return DataCell(extractor(item));

What happens is that those elements lose their types. When I call widget.data I get type


And for widget.colExtractors it's:

List<dynamic Function(dynamic)>

As you can see in the method the trick with 'as' was enough and it behaves properly for widget.data, it doesn't work for colExtractors. I'm getting:

Unnecessary cast.

Without 'as' I'm gerring compilation error:

Expected a value of type 'List<(dynamic) => dynamic>', but got one of type 'List<(PassedType) =>

What is the way to correct it and why does it behave this way?

Plase help

Read more here: https://stackoverflow.com/questions/64955729/typing-problem-in-flutter-while-getting-widget-data

Content Attribution

This content was originally published by artoniaz at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: