Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

ElevatedButton(
                          onPressed: () {
                            Navigator.of(context).pushNamed(
                              OcrScreen.routeName,
                              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'];

Later

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am putting this list into CarouselSlider:

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

        controller: _titleController,
    autofocus: false,
    style: TextStyle(fontSize: 22.0, color: Colors.black),
        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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading