List<dynamic> is not a subtype of type List<Widget>?


I am trying CarouselSlider.I want to make the upside Carousel Slider,bottom side TextFormField. I am holding a list of image paths in selected and send to the screen like this:

                          onPressed: () {
                              arguments: {'image': selected},

After that I am taking arguments in other screen like this:

final args = ModalRoute.of(context)!.settings.arguments as Map;
    final images=args['image'];


I am putting this list into CarouselSlider:

return Scaffold(extendBodyBehindAppBar: false,
      appBar: AppBar(
        title: const Text('OCR'),
        elevation: 0,
        backgroundColor: Colors.transparent,
    child: CarouselSlider(
    options: CarouselOptions(),
      items: images
          .map((image) => Container(
        child: Center(
            Image.file(File(image),fit: BoxFit.cover, width: 1000)),
        keyboardType: TextInputType.multiline,

        controller: _titleController,
    autofocus: false,
    style: TextStyle(fontSize: 22.0, color:,
        maxLines: 20,
    decoration: InputDecoration(
    filled: true,
      isDense: true,

      contentPadding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),

      fillColor: Colors.white,


I am getting List is not a subtype of type List? error and I couldn’t find the solution for this error can anyone help me to find a solution?

>Solution :

Seems like args['image'] can be null that’s why you get this error because items should be of type List<Widget>. Try creating the variable this way.

final List<String> images = args['image'] ?? [];

However, you may want to check first if images.isNotEmpty beforing mapping it.

Leave a Reply Cancel reply