问题描述
在将 Flutter 更新到最新版本后,我在 Carousel
上收到此异常。 Carousel
在 Flutter 1.22.4 版上运行良好。但是在切换到最新版本(2.0.3)时,我收到了这个异常。下面是代码和异常。我正在使用下面的包
https://pub.dev/packages/carousel_pro
例外
======== 渲染库捕获的异常 ================================= 在 performlayout() 期间抛出了以下 NoSuchMethodError: getter 'key' 被调用为 null。 接收器:空 尝试调用:key
相关的导致错误的小部件是 Carousel lib\…\homeViews\homeAppBarDelegate.dart:39 当异常发生时 抛出,这是堆栈 #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。包:Flutter/…/widgets/sliver.dart:1214 #4 BuildOwner.buildScope package:Flutter/.../widgets/framework.dart:2647 ... 以下 引发异常时正在处理 RenderObject: RenderSliverFillViewport#4a87d relayoutBoundary=up2 NEEDS-LAYOUT 需要油漆渲染对象:RenderSliverFillViewport#4a87d relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT parentData:paintOffset=Offset(0.0,0.0)(可以使用size) 约束:SliverConstraints(AxisDirection.right,GrowthDirection.forward,ScrollDirection.idle,scrollOffset: 0.0,剩余PaintExtent:411.4,crossAxisExtent:230.0, crossAxisDirection: AxisDirection.down,viewportMainAxisExtent: 411.4,剩余CacheExtent:411.4,cacheOrigin:0.0) 几何:空 没有孩子当前生活==================================== ===================================
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
,我看不到您将此列表的值传递到何处,或者您的小部件树从何处获取它。