如何解决SingleChildScrollView 控制器与否
问题:只要控制器设置为SingleChildScrollView,页面的交互形式就会发生变化。以我有限的 Flutter 经验,请帮忙解决这个问题。谢谢!
未设置controller时,如图1,设置Controller时,如图2 我想要实现的是图1,但我需要使用Controller。当我点击Tabbar时,我使用Controller设置了SingleChildScrollView的偏移量,但是一旦设置了Controller,交互就变成了图2
我尝试了多种变体,但似乎都不起作用。有什么想法吗?
主页代码
@override
Widget build(BuildContext context) {
[enter image description here][1]_width = MediaQuery.of(context).size.width;
model = ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: ...
body: StreamBuilder(
stream: _streamController.stream,builder:
(BuildContext context,AsyncSnapshot<ZshBrandModel> snapshot) {
if (snapshot.hasData) {
return NestedScrollView(
headerSliverBuilder:
(BuildContext context,bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,backgroundColor: Colors.white,pinned: true,floating: true,expandedHeight: 460,flexibleSpace: FlexibleSpaceBar(
stretchModes: [StretchMode.zoomBackground],collapseMode: CollapseMode.pin,background: Container(
height: 100,color: Colors.white,padding: EdgeInsets.only(bottom: 45),child: singleScroll(snapshot.data),),bottom: TabBar(
labelPadding: EdgeInsets.zero,tabs: tabList.map((e) {
return Tab(text: e);
}).toList(),controller: _tabController,indicatorColor: Colors.red,unselectedLabelColor: Colors.grey,labelColor: Colors.red,indicatorSize: TabBarIndicatorSize.tab,indicatorPadding:
EdgeInsets.only(left: 20,right: 20,bottom: 0),// indicatorSize: TabBarIndicatorSize.label,onTap: (idx) {
...
},)
];
},body: snapshot.hasData
? NotificationListener(
onNotification: (ScrollNotification notification) {
...
return true;
},child: BrandBottomListContent(
onChange: (value) => onChanged(value),controller: _controller,)
: Center(child: CircularProgressIndicator()));
} else {
return Center(child: Text("正在请求数据...."));
}
},));
}
ListView 代码:
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
controller: controller,key: globalKeyList,child: Column(
children: [
Column(
key: globalKey1,children: [
buildTitle(""),Container(
height: 900,child: Center(
child: Text(
"",style: Theme.of(context).textTheme.headline6,Container(
padding: EdgeInsets.all(8),child: Text(
""),)
],Column(
key: globalKey2,style: Theme.of(context).textTheme.headline4,Container(
child: Text(
""),Column(
key: globalKey3,Column(
key: globalKey4,Column(
key: globalKey5,],);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。