Home > Back-end >  Type 'List<Widget?>' is not a subtype of type 'List<Widget>'
Type 'List<Widget?>' is not a subtype of type 'List<Widget>'

Time:11-21

I'm using connectivity_wrapper: ^1.0.6 in flutter application. while passing child to connectivity_wrapper it generates an error type 'List<Widget?>' is not a subtype of type 'List' in type cast I have googled it but not able to find any solution. and also want to know the difference between List<Widget?> and 'List.

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: appBarCustom(
    onBackTap: onBackTab,
    color: Colors.black,
    title: Strings.appName,
    textStyle: TextStyles.appBarBold,
    actions: [
      C0(),
    ],
  ),
  body: ConnectivityWidgetWrapper(
    child: ListView(
      children: <Widget>[
        ListTile(
          title: Text("EX1"),
          onTap: () {

          },
        ),
        Divider(),
        ListTile(
          title: Text("EX@"),
          onTap: () {

          },
        ),
        Divider(),
      ],
    ),
  ),
);
}

Error: type 'List<Widget?>' is not a subtype of type 'List' in type cast

CodePudding user response:

there is an issue in github.so track that issue to solve your problem. it's all about null safety.

CodePudding user response:

List and List<Widget> are different because when you write only List the compiler understand that you want a list of dynamics and it behaves accordingly, now List<Widget> is a way to say to the compiler hey this list is a list of widgets so if I forgot and I put a string or an int or any other type rather than widget remind me to don't do that

Example :

List numbers = [1,"hi",Container()]; //equivalent to List<dynamic> 
List<Widget> containers = [Container() , Container(), SizedBox()] //list only of widgets

also Widget and Widget? are differents because Widget? can't be nullable this has been introduced in the null safety version of flutter.

Now moving to your main question, I used the link provided in the first answer and I found that there is a fix for that : https://github.com/ajaykumargithub2114/connectivity_wrapper/issues/8#issuecomment-819902761 but I don't recommend you to change the code of package, it's better to wait until the next release to get a fix for that

  • Related