Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The return type 'Widget?' isn't a 'Widget', as required by the closure's context

I am using consumer widget to avoid re-rendering before null safety it works fine... But when I upgrade provider package to it gives me an error which I mentioned above it is not accepting ListView.builder() and says that The return type Widget? isn't a Widget, as required by the closure's context


Consumer<GreatPlaces>(
        child: Center(
          child: const Text(
            'Got no places yet, start adding some',
          ),
        ),
        builder: (ctx, greatPlaces, ch) => greatPlaces.items.length <= 0
            ? ch
            : ListView.builder(          ***//Here I got error***
                itemBuilder: (ctx, index) => Center(),
                itemCount: 5,
              ),
      ),
like image 816
x86 Avatar asked Feb 03 '26 05:02

x86


1 Answers

Use null-assert ! operation on ch!

 data.state.length <= 0
          ? child!
          : ListView.builder(
              itemBuilder: (context, index) => Container(),
              itemCount: 4,
            );
like image 120
Yeasin Sheikh Avatar answered Feb 04 '26 22:02

Yeasin Sheikh