Android NestedScrollView问题,在两个屏幕之间切换时引发错误
我对NestedScrollView有一些问题。我使用BottomNavigationBar实现了PageView,有时在两个屏幕之间切换时,会出现以下错误: 'package:flatter/src/widgets/nested_scroll_view.dart':失败的断言:第501行位置14:'position.minScrollExtent!=null&&position.pixels!=null”:不正确Android NestedScrollView问题,在两个屏幕之间切换时引发错误,android,flutter,dart,nestedscrollview,Android,Flutter,Dart,Nestedscrollview,我对NestedScrollView有一些问题。我使用BottomNavigationBar实现了PageView,有时在两个屏幕之间切换时,会出现以下错误: 'package:flatter/src/widgets/nested_scroll_view.dart':失败的断言:第501行位置14:'position.minScrollExtent!=null&&position.pixels!=null”:不正确 child:NestedScrollView( 控制器:_控制器, heade
child:NestedScrollView(
控制器:_控制器,
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
自动嵌入:false,
对,,
扩展高度:140.0,
浮动:假,
标题:对,
flexibleSpace:FlexibleSpaceBar(
标题:对,
背景:新容器(
孩子:未来建设者(
future:CoverImagesApi().getImageFile(1),
生成器:(上下文,快照){
如果(snapshot.data!=null){
返回容器(
子:列(
儿童:[
扩大(
弹性:5,
子:容器(
对齐:alignment.topCenter,
),
),
扩大(
弹性:2,
子容器:新容器(
儿童:中心(
儿童:文本(“Obecnátabuľa”,
样式:TextStyle(
字体大小:26.0,
fontWeight:fontWeight.bold
),
textAlign:textAlign.center,
),
),
装饰:盒子装饰(
颜色:color.fromRGBO(255、255、255、0.8)
),
对齐:alignment.bottomCenter,//上面的变量
)
),
],
),
装饰:新盒子装饰(
图片:新装饰图片(
适合:BoxFit.cover
image:snapshot.data.existsSync()?image.file(snapshot.data)。image:AssetImage('assets/tabla.jpg'),
),
),
);
}否则{
返回容器(高度:0.0,宽度:0.0);
}
}
),
),
),
),
];
},
主体:数据填充器(脚手架钥匙:_脚手架钥匙),
)
有人有什么想法吗?这没有问题,只要热重启就可以解决问题。这是因为热重新加载不会更改应用程序的状态,并且您执行了一个动作,该动作从不存在的状态中提取(假定存在)
如果所有其他操作都失败,请尝试清理应用程序,这应该很好,因为我有4个选项卡。其中两个我有
ScrollController
用于ListView
,但另外两个没有ScrollController
,但有Grid
。帮助我的是将ScrollController
添加到那些Grid
s中。也许这个建议可以帮助人们在缺少的地方添加ScrollController。我使用的是extendBody:true,在scaffold内部,并且得到了相同的错误。删除后,错误得到解决。只需将键:UniqueKey()
添加到NestedScrollView即可
您的代码将被删除
child: NestedScrollView(
key: UniqueKey()
controller: _controller,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,
pinned: true,
expandedHeight: 140.0,
floating: false,
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: new Container(
child: FutureBuilder(
future: CoverImagesApi().getImageFile(1),
builder: (context, snapshot) {
if(snapshot.data != null) {
return Container(
child: Column(
children: <Widget>[
Expanded(
flex: 5,
child: Container(
alignment: Alignment.topCenter,
),
),
Expanded(
flex: 2,
child: new Container(
child: Center(
child: Text('Obecná tabuľa',
style: TextStyle(
fontSize: 26.0,
fontWeight: FontWeight.bold
),
textAlign: TextAlign.center,
),
),
decoration: BoxDecoration(
color: Color.fromRGBO(255, 255, 255, 0.8)
),
alignment: Alignment.bottomCenter, //variable above
)
),
],
),
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover
image: snapshot.data.existsSync() ? Image.file(snapshot.data).image : AssetImage('assets/tabula.jpg'),
),
),
);
} else {
return Container(height: 0.0, width: 0.0);
}
}
),
),
),
),
];
},
body: DataFiller(scaffoldKey: _scaffoldKey),
)
child:NestedScrollView(
关键字:UniqueKey()
控制器:_控制器,
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
自动嵌入:false,
对,,
扩展高度:140.0,
浮动:假,
标题:对,
flexibleSpace:FlexibleSpaceBar(
标题:对,
背景:新容器(
孩子:未来建设者(
future:CoverImagesApi().getImageFile(1),
生成器:(上下文,快照){
如果(snapshot.data!=null){
返回容器(
子:列(
儿童:[
扩大(
弹性:5,
子:容器(
对齐:alignment.topCenter,
),
),
扩大(
弹性:2,
子容器:新容器(
儿童:中心(
儿童:文本(“Obecnátabuľa”,
样式:TextStyle(
字体大小:26.0,
fontWeight:fontWeight.bold
),
textAlign:textAlign.center,
),
),
装饰:盒子装饰(
颜色:color.fromRGBO(255、255、255、0.8)
),
对齐:alignment.bottomCenter,//上面的变量
)
),
],
),
装饰:新盒子装饰(
图片:新装饰图片(
适合:BoxFit.cover
我
child: NestedScrollView(
key: UniqueKey()
controller: _controller,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,
pinned: true,
expandedHeight: 140.0,
floating: false,
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: new Container(
child: FutureBuilder(
future: CoverImagesApi().getImageFile(1),
builder: (context, snapshot) {
if(snapshot.data != null) {
return Container(
child: Column(
children: <Widget>[
Expanded(
flex: 5,
child: Container(
alignment: Alignment.topCenter,
),
),
Expanded(
flex: 2,
child: new Container(
child: Center(
child: Text('Obecná tabuľa',
style: TextStyle(
fontSize: 26.0,
fontWeight: FontWeight.bold
),
textAlign: TextAlign.center,
),
),
decoration: BoxDecoration(
color: Color.fromRGBO(255, 255, 255, 0.8)
),
alignment: Alignment.bottomCenter, //variable above
)
),
],
),
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover
image: snapshot.data.existsSync() ? Image.file(snapshot.data).image : AssetImage('assets/tabula.jpg'),
),
),
);
} else {
return Container(height: 0.0, width: 0.0);
}
}
),
),
),
),
];
},
body: DataFiller(scaffoldKey: _scaffoldKey),
)