简体   繁体   English

在最新版本的 flutter 上使用轮播时,在 null 上调用了 getter 'key'

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

I'm getting this exception on Carousel after updating flutter to the latest version.将 flutter 更新到最新版本后,我在Carousel上遇到了这个异常。 Carousel was working fine on flutter version 1.22.4. Carousel在 flutter 版本 1.22.4 上运行良好。 But upon switching to latest version (2.0.3), I'm getting this exception.但是在切换到最新版本(2.0.3)时,我得到了这个例外。 Below are the code and exception.下面是代码和异常。 I'm using the below package https://pub.dev/packages/carousel_pro我正在使用以下 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. ════════ 渲染库捕获的异常══════════════════════════════S═下面的方法是═══S═在 performLayout() 期间抛出:在 null 上调用了 getter 'key'。 Receiver: null Tried calling: key接收方:null 尝试呼叫: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. 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 ════════════════════════════════════════════════════════════════════════════════ 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) (可以使用大小) 约束: SliverConstraints(AxisDirection.right, GrowthDirection.forward, ScrollDirection 。 ══════════════════════════════════════════════════ ════════════════════

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获取空白屏幕

在此处输入图像描述

The error is saying geometry: null no children current live .错误是说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.在运行小部件之前填充您的项目,或者在渲染之前使用isNotEmpty检查,这应该可以解决您的问题。 Specifically coverImagesList , I can't see where you are passing the values of this list or where your widget tree is getting it from.特别coverImagesList ,我看不到你在哪里传递这个列表的值或者你的小部件树从哪里得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM