繁体   English   中英

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

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

将 flutter 更新到最新版本后,我在Carousel上遇到了这个异常。 Carousel在 flutter 版本 1.22.4 上运行良好。 但是在切换到最新版本(2.0.3)时,我得到了这个例外。 下面是代码和异常。 我正在使用以下 package https://pub.dev/packages/carousel_pro

例外

════════ 渲染库捕获的异常══════════════════════════════S═下面的方法是═══S═在 performLayout() 期间抛出:在 null 上调用了 getter '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. 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 。 ══════════════════════════════════════════════════ ════════════════════

代码

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,
                      ),
                    ),
                  ],
                ),
              ],
            ),

获取空白屏幕

在此处输入图像描述

错误是说geometry: null no children current live 你的小部件没有收到任何孩子,你能确认这不是问题吗? 在运行小部件之前填充您的项目,或者在渲染之前使用isNotEmpty检查,这应该可以解决您的问题。 特别coverImagesList ,我看不到你在哪里传递这个列表的值或者你的小部件树从哪里得到它。

暂无
暂无

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

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