'_Type' is not a subtype of type 'Widget'

Your mistake is that you returned the type instead of the instance of a given type:

return Foo;

vs

return Foo();

I have faced a very similar problem with error info '' when having following code:


    List<Widget> items = ['1', '2', '3', '4']
        .map(
          (f) {
            return Text(f);
          },
        )
        .toList();
    items.last = Stack(
      children: <Widget>[items.last],
    );

change this code to following works:


    List<Widget> items = ['1', '2', '3', '4']
        .map(
          (f) {
            return Text(f);
          },
        )
        .cast<Widget>()
        .toList();
    items.last = Stack(
      children: <Widget>[items.last],
    );

I think maybe when doing a map, the result type from map function is changed, so the internal dart implemention of list assert fail. Force the cast type works.


Also, this error is very common when you are moving across screens and using network data to be displayed in your apps, using ternary operator for data and progress indicator then the indicator must be called as a Widget LinearProgressIndicator() and not LinearProgressIndicator.

Tags:

Widget

Flutter