Search code examples
fluttercarousel-slider

Flutter carousel_slider 4.0.0 error type 'Null' is not a subtype of type 'List<int>' in type cast


I'm using my flutter (null safety version) app for carousel_slider 4.0.0 , slider worked but, I faced this error

type 'Null' is not a subtype of type 'List' in type cast

any solution for this?

enter image description here my code here

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_svg/svg.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:rmapp/provider/theme_provider.dart';

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  //swiper current index

  late final List<String> imageList = [
    "https://www.setaswall.com/wp-content/uploads/2018/08/Spiderman-Wallpaper-76-1280x720.jpg",
    "https://lh3.googleusercontent.com/proxy/yL2FmQfZA79S5eIDza9MH2NjKGIKWPOGRHxHdYwiNPcYDW26YmK6qnP01ZDLsBENZpiADc1ohkj3LzVjrwoX8Pb-crT6MYZb3Jp9gy3ZrlET_yvoFS0qtUHLq4DtVPcqIdxPiNWI_j08omBVACv-YJc",

  ];
  @override
  Widget build(BuildContext context) {
    Provider.of<ThemeProvider>(context).themeMode == ThemeMode.dark
        ? 'DarkTheme'
        : 'LightTheme';
    return Scaffold(
      // Setting up AppBar
      appBar: AppBar(
        automaticallyImplyLeading: false,
        iconTheme: Theme.of(context).iconTheme,

       

      ),

      // Setting up Background Color


      // Body
      body: Container(
        child: ListView(
          physics: ClampingScrollPhysics(),
          children: <Widget>[

            Padding(
              padding: EdgeInsets.only(left: 16, bottom: 10, top: 10,),
              child: Text(
                'Hi, Welcome back!',
                //style: mTitleStyle,
              ),
            ),
            //Promo Slider
            _promoSlider(),

          ],
        ),
      ),
    );
  }


  //Promo Slider
  Widget _promoSlider() {
    return Container(



            child: CarouselSlider(
              options: CarouselOptions(
                enlargeCenterPage: true,
                enableInfiniteScroll: false,
                autoPlay: true,
              ),
              items: imageList.map((e) => ClipRRect(
                borderRadius: BorderRadius.circular(8),
                child: Stack(
                  fit: StackFit.expand,
                  children: <Widget>[
                    Image.network(e,
                      width: 1050,
                      height: 350,
                      fit: BoxFit.cover,)
                  ],
                ) ,
              )).toList(),
                ),);

  }

}

Solution

  • This error could indicate that something in your imageList is null. The CarouselSlider requires non null parameters for key / value purposes in its items attribute.