Home > Software design >  The argument type 'List<InkWell?>' can't be assigned to the parameter type 
The argument type 'List<InkWell?>' can't be assigned to the parameter type 

Time:04-26

I have a problem with models flutter project that I have.. I get an error:

The argument type 'List<InkWell?>' can't be assigned to the parameter type 'List'.

          child: GridView.count(
            crossAxisCount: gridCount,
            crossAxisSpacing: 16,
            mainAxisSpacing: 16,
            children: filmModelList.map((film) {
              if (film.isFavorite == true) {
                return InkWell(
                  onTap: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) {
                      return DetailScreen(
                        film: film,
                      );
                    }));
                  },
                  child: Container(...));
              } else {

              }
            }).toList(),
          ),

error in this part:

children: filmModelList.map((film)

CodePudding user response:

child: GridView.count(
            crossAxisCount: gridCount,
            crossAxisSpacing: 16,
            mainAxisSpacing: 16,
            children: filmModelList.map((film) {
              if (film.isFavorite == true) {
                return InkWell(
                  onTap: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) {
                      return DetailScreen(
                        film: film,
                      );
                    }));
                  },
                  child: Container(...));
              } else {
                return Sizedbox();
              }
            }).toList(),
          ),

CodePudding user response:

Try to look at GridView.count children parameter it requires list of widget,In your else part you should return some widget.

      child: GridView.count(
        crossAxisCount: gridCount,
        crossAxisSpacing: 16,
        mainAxisSpacing: 16,
        children: filmModelList.map((film) {
          if (film.isFavorite == true) {
            return InkWell(
              onTap: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return DetailScreen(
                    film: film,
                  );
                }));
              },
              child: Container(...));
          } else {
              return SomeWidget();
          }
        }).toList(),
      ),
  • Related