The getter 'key' was called on null while using Carousel on latest version of flutter

192

The error is saying geometry: null no children current live. You widget isn't receiving any children, can you confirm that this is not the issue? Populate your items before running the widget, or check using isNotEmpty before rendering it, that should solve your problem. Specifically coverImagesList, I can't see where you are passing the values of this list or where your widget tree is getting it from.

Share:
192
Faizan Kamal
Author by

Faizan Kamal

Updated on December 20, 2022

Comments

  • Faizan Kamal
    Faizan Kamal over 1 year

    I'm getting this exception on Carousel after updating flutter to the latest version. Carousel was working fine on flutter version 1.22.4. But upon switching to latest version (2.0.3), I'm getting this exception. Below are the code and exception. I'm using the below package https://pub.dev/packages/carousel_pro

    Exception

    ════════ Exception caught by rendering library ═════════════════════════════════ The following NoSuchMethodError was thrown during performLayout(): The getter 'key' was called on null. Receiver: null Tried calling: key

    The relevant error-causing widget was Carousel lib\…\homeViews\homeAppBarDelegate.dart:39 When the exception was thrown, this was the stack #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) #1 SliverChildListDelegate.build package:flutter/…/widgets/sliver.dart:722 #2 SliverMultiBoxAdaptorElement._build package:flutter/…/widgets/sliver.dart:1201 #3 SliverMultiBoxAdaptorElement.createChild. package:flutter/…/widgets/sliver.dart:1214 #4 BuildOwner.buildScope package:flutter/…/widgets/framework.dart:2647 ... The following RenderObject was being processed when the exception was fired: RenderSliverFillViewport#4a87d relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT RenderObject: RenderSliverFillViewport#4a87d relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT parentData: paintOffset=Offset(0.0, 0.0) (can use size) constraints: SliverConstraints(AxisDirection.right, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 411.4, crossAxisExtent: 230.0, crossAxisDirection: AxisDirection.down, viewportMainAxisExtent: 411.4, remainingCacheExtent: 411.4, cacheOrigin: 0.0) geometry: null no children current live ════════════════════════════════════════════════════════════════════════════════

    Code

    class HomeView extends StatefulWidget {
      @override
      _HomeViewState createState() => _HomeViewState();
    }
    
    class _HomeViewState extends State<HomeView> {
      @override
    Widget build(BuildContext context) {
    return Scaffold(
          ...................
    Stack(
        children: [
            CustomScrollView(
              controller: _scrollController,
              slivers: <Widget>[
               SliverPersistentHeader(
                    delegate: HomeAppBarDelegate(
                        maxExtent: 230,
                        minExtent: 50,
                    ),
                    pinned: true,
                    floating: false,
                 ),
              ],
           ),
        ],
       ),
    ),    
    },
    }
    
    import 'package:carousel_pro/carousel_pro.dart';
    
    class HomeAppBarDelegate extends SliverPersistentHeaderDelegate {
      @override
      Widget build(
          BuildContext context, double shrinkOffset, bool overlapsContent) {
    
    return Stack(
         children: [
          ...................
    
            // ------------------------------ C O V E R   B L U R   I M A G E S
            Carousel(
               animationCurve: Curves.easeInOutQuint,
               animationDuration: Duration(seconds: 1),
               dotBgColor: Colors.transparent,
               overlayShadow: true,
               autoplayDuration: Duration(seconds: 4),
               showIndicator: false,
               dotIncreasedColor: Colors.brown,
               onImageChange: (prevInd, currInd) => coverImgIndex = currInd,
               images: [
                  ...coverImagesList.map(
                    (singleImg) => HomeBlurCoverImg(
                     imgURl: singleImg,
                     animationVal: animationVal,
                     maxExtent: maxExtent,
                     sizingInformation: sizingInformation,
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
    

    Getting blank screen

    enter image description here

  • Faizan Kamal
    Faizan Kamal about 3 years
    yup that's exactly what it was. Thanks