Flutter ';FindEnderObject';在null上调用了。键为.currentContext.FindEnderObject()的SliverList,
我试图制作一个粘滞的TabBar,当我按下它的任何一个标签,向下滚动到它的一部分时,我用粘滞条和滚动键实现了这一点。它可以工作,但是当我从顶部到底部,或者从底部到底部,或者当我有一个高度很大的零件时,它告诉我'FindEnderObject'被调用为null 这是我的银色代理代码Flutter ';FindEnderObject';在null上调用了。键为.currentContext.FindEnderObject()的SliverList,,flutter,flutter-layout,flutter-sliver,Flutter,Flutter Layout,Flutter Sliver,我试图制作一个粘滞的TabBar,当我按下它的任何一个标签,向下滚动到它的一部分时,我用粘滞条和滚动键实现了这一点。它可以工作,但是当我从顶部到底部,或者从底部到底部,或者当我有一个高度很大的零件时,它告诉我'FindEnderObject'被调用为null 这是我的银色代理代码 class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { _SliverAppBarDelegate({ @required
class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
_SliverAppBarDelegate({
@required this.minHeight,
@required this.maxHeight,
@required this.child,
});
final double minHeight;
final double maxHeight;
final Widget child;
@override
double get minExtent => minHeight;
@override
double get maxExtent => math.max(maxHeight, minHeight);
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return new SizedBox.expand(child: child);
}
@override
bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight ||
minHeight != oldDelegate.minHeight ||
child != oldDelegate.child;
}
}
下面是我的slivers小部件主体代码
body: CustomScrollView(
controller: scrollController,
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
[
Container(
height: data.size.height / 3,
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
imgs[index],
fit: BoxFit.fill,
);
},
indicatorLayout: PageIndicatorLayout.COLOR,
autoplay: true,
itemCount: imgs.length,
pagination: new SwiperPagination(
margin: new EdgeInsets.all(5.0),
builder: new DotSwiperPaginationBuilder(
color: Colors.grey.shade400,
activeColor: yumColors.pink)),
)),
],
),
),
makeTabBarHeader(),
SliverList(
key: sliverListtKey,
delegate: SliverChildListDelegate(
[
Padding(padding: const EdgeInsets.all(8.0), child: Container()),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 900,
child: Card(
color: yumColors.pink,
key: overKey,
child: Center(
child: Text(
"Overview",
style: TextStyle(
color: Colors.white,
fontSize: 3 * SizeConfig.textMultiplier),
)),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 900,
child: Card(
key: revKey,
color: yumColors.pink,
child: Center(
child: Text(
"Reviews",
style: TextStyle(
color: Colors.white,
fontSize: 3 * SizeConfig.textMultiplier),
)),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 900,
child: Card(
key: menuKey,
color: yumColors.pink,
child: Center(
child: Text(
"Menu",
style: TextStyle(
color: Colors.white,
fontSize: 3 * SizeConfig.textMultiplier),
)),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 900,
child: Card(
key: contactKey,
color: yumColors.pink,
child: Center(
child: Text(
"Contact",
style: TextStyle(
color: Colors.white,
fontSize: 3 * SizeConfig.textMultiplier),
)),
),
),
),
Padding(padding: const EdgeInsets.all(8.0), child: Container()),
],
),
),
],
),
);
body:CustomScrollView(
控制器:滚动控制器,
条子:[
银表(
委托:SliverChildListDelegate(
[
容器(
高度:data.size.height/3,
孩子:新泳衣(
itemBuilder:(构建上下文,int索引){
返回新的Image.asset(
imgs[索引],
fit:BoxFit.fill,
);
},
indicatorLayout:PageIndicatorLayout.COLOR,
自动播放:对,
itemCount:imgs.length,
分页:新的SwiperPagination(
边距:所有新边集(5.0),
生成器:新的点分页生成器(
颜色:Colors.grey.shade400,
activeColor:yumColors.pink),
)),
],
),
),
makeTabBarHeader(),
银表(
键:SliverListKey,
委托:SliverChildListDelegate(
[
Padding(Padding:const-EdgeInsets.all(8.0),child:Container()),
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:900,
孩子:卡片(
颜色:yumColors.粉红色,
关键:过度关键,
儿童:中心(
子:文本(
“概述”,
样式:TextStyle(
颜色:颜色,白色,
fontSize:3*SizeConfig.textMultiplier),
)),
),
),
),
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:900,
孩子:卡片(
键:revKey,
颜色:yumColors.粉红色,
儿童:中心(
子:文本(
“评论”,
样式:TextStyle(
颜色:颜色,白色,
fontSize:3*SizeConfig.textMultiplier),
)),
),
),
),
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:900,
孩子:卡片(
关键:梅努基,
颜色:yumColors.粉红色,
儿童:中心(
子:文本(
“菜单”,
样式:TextStyle(
颜色:颜色,白色,
fontSize:3*SizeConfig.textMultiplier),
)),
),
),
),
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:900,
孩子:卡片(
键:contactKey,
颜色:yumColors.粉红色,
儿童:中心(
子:文本(
“联系人”,
样式:TextStyle(
颜色:颜色,白色,
fontSize:3*SizeConfig.textMultiplier),
)),
),
),
),
Padding(Padding:const-EdgeInsets.all(8.0),child:Container()),
],
),
),
],
),
);
}
}
这是我的粘性标签条代码
SliverPersistentHeader makeTabBarHeader() {
return SliverPersistentHeader(
pinned: true,
delegate: _SliverAppBarDelegate(
minHeight: 60.0,
maxHeight: 60.0,
child: Container(
color: Colors.white,
child: TabBar(
onTap: (val) {
switch (val) {
case 0:
{
scrollController.position.ensureVisible(
overKey.currentContext.findRenderObject(),
alignment:
0.0, // How far into view the item should be scrolled (between 0 and 1).
duration: const Duration(seconds: 1),
);
}
break;
case 1:
{
scrollController.position.ensureVisible(
revKey.currentContext.findRenderObject(),
alignment:
0.0, // How far into view the item should be scrolled (between 0 and 1).
duration: const Duration(seconds: 1),
);
}
break;
case 2:
{
scrollController.position.ensureVisible(
menuKey.currentContext.findRenderObject(),
alignment:
0.0, // How far into view the item should be scrolled (between 0 and 1).
duration: const Duration(seconds: 1),
);
}
break;
case 3:
{
scrollController.position.ensureVisible(
contactKey.currentContext.findRenderObject(),
alignment:
0.0, // How far into view the item should be scrolled (between 0 and 1).
duration: const Duration(seconds: 1),
);
}
break;
}
},
unselectedLabelColor: Colors.grey.shade700,
indicatorColor: yumColors.pink,
indicatorWeight: 2.0,
labelColor: yumColors.pink,
controller: _tabController,
tabs: <Widget>[
new Tab(
child: Text(
"Overview",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 1.6 * SizeConfig.textMultiplier),
),
),
new Tab(
child: Text(
"Reviews",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 1.6 * SizeConfig.textMultiplier),
),
),
new Tab(
child: Text(
"Menu",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 1.6 * SizeConfig.textMultiplier),
),
),
new Tab(
child: Text(
"Contact",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 1.6 * SizeConfig.textMultiplier),
),
),
],
indicatorSize: TabBarIndicatorSize.tab,
),
),
),
);
SliverPersistentHeader makeTabBarHeader(){
回程滑动头(
对,,
代表:_SliverAppBarDelegate(
最小高度:60.0,
最大高度:60.0,
子:容器(
颜色:颜色,白色,
孩子:TabBar(
onTap:(val){
开关(val){
案例0:
{
scrollController.position.Ensuverible(
overKey.currentContext.FindEnderObject(),
对齐:
0.0,//项目应滚动到视图的范围(介于0和1之间)。
持续时间:常数持续时间(秒数:1),
);
}
打破
案例1:
{
scrollController.position.Ensuverible(
revKey.currentContext.FindEnderObject(),
对齐:
0.0,//项目应滚动到视图的范围(介于0和1之间)。
持续时间:常数持续时间(秒数:1),
);
}
打破
案例2:
{
scrollController.position.Ensuverible(
menuKey.currentContext.FindEnderObject(),
对齐:
0.0,//项目应滚动到视图的范围(介于0和1之间)。
持续时间:常数持续时间(秒数:1),
);
}
打破
案例3:
{
scrollController.position.Ensuverible(
contactKey.currentContext.FindEnderObject(),
对齐:
0.0,//项目应滚动到视图的范围(介于0和1之间)。
持续时间:常数持续时间(秒数:1),
);
}
打破
}