Flutter 我怎样才能使整个页面可滚动?
我一直在想如何解决这个问题。 我想实现的是使整个页面可滚动。 所以,当您向下滚动时,页面顶部将不可见,并且只有Flutter 我怎样才能使整个页面可滚动?,flutter,flutter-layout,Flutter,Flutter Layout,我一直在想如何解决这个问题。 我想实现的是使整个页面可滚动。 所以,当您向下滚动时,页面顶部将不可见,并且只有TabBarView可见。 我有这个代码 return DefaultTabController( length: 3, child: Scaffold( appBar: AppBar( elevation: 0.0, backgroundColor: Colors.white, ), body: ListView( shrink
TabBarView
可见。我有这个代码
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.white,
),
body: ListView(
shrinkWrap: true,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 30.0, 15.0, 5.0),
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(backgroundImage: NetworkImage('https://images.unsplash.com/photo-1543194094-3fb5703804d5?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=cb818de45a33597672b648166ce73764&auto=format&fit=crop&w=500&q=60'), radius: 42.0),
title: RaisedButton(
textColor: Colors.white,
child: Text(
'Edit Profile',
maxLines: 1,
),
color: Theme.of(context).primaryColor,
onPressed: () {},
),
),
Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 5.0, left: 30.0),
child: Row(
children: <Widget>[
Flexible(
child: Text(
'Spider-Man',
style: const TextStyle(fontSize: 16.0),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 1.0),
Icon(Icons.check_circle, size: 16.0, color: Theme.of(context).primaryColor),
],
),
),
],
),
),
Container(
width: double.infinity,
height: 40.0,
decoration: const BoxDecoration(color: Colors.white),
child: TabBar(
controller: _controller,
labelColor: Colors.black,
indicatorColor: Theme.of(context).primaryColor,
unselectedLabelColor: Colors.grey,
tabs: [
Tab(text: 'Following'),
Tab(text: 'Follower'),
Tab(text: 'Likes'),
],
),
),
Expanded(
child: TabBarView(
physics: const NeverScrollableScrollPhysics(),
controller: _controller,
children:
[
Center(
child: Text('Following'),
),
Center(
child: Text('Follower'),
),
ListView.builder(
itemCount: 100,
itemExtent: 100.0,
itemBuilder: (c ,i) {
return Center(
child: Text(i.toString())
);
},
)
]
),
)
],
)
),
);
返回DefaultTabController(
长度:3,
孩子:脚手架(
appBar:appBar(
标高:0.0,
背景颜色:Colors.white,
),
正文:ListView(
收缩膜:对,
儿童:[
填充物(
填充:LTRB(15.0,30.0,15.0,5.0)中的常数边集,
子:列(
儿童:[
列表砖(
前导:CircleAvatar(背景图像:NetworkImage()https://images.unsplash.com/photo-1543194094-3fb5703804d5?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=cb818de45a33597672b648166ce73764&auto=format&fit=crop&w=500&q=60'),半径:42.0),
标题:RaisedButton(
textColor:Colors.white,
子:文本(
“编辑配置文件”,
maxLines:1,
),
颜色:主题。背景。原色,
按下:(){},
),
),
填充物(
填充:仅限常量边集(顶部:22.0,底部:5.0,左侧:30.0),
孩子:排(
儿童:[
灵活的(
子:文本(
“蜘蛛侠”,
样式:常量文本样式(fontSize:16.0),
溢出:TextOverflow.省略号,
),
),
const SizedBox(宽度:1.0),
图标(Icons.check_圆圈,大小:16.0,颜色:Theme.of(context.primaryColor)),
],
),
),
],
),
),
容器(
宽度:double.infinity,
身高:40.0,
装饰:const BOX装饰(颜色:颜色。白色),
孩子:TabBar(
控制器:_控制器,
labelColor:Colors.black,
指示色:主题。背景。原色,
未选择的标签颜色:Colors.grey,
选项卡:[
选项卡(文本:“以下”),
选项卡(文本:“跟随者”),
选项卡(文本:“Likes”),
],
),
),
扩大(
子项:选项卡视图(
物理学:const NeverScrollableScrollPhysics(),
控制器:_控制器,
儿童:
[
居中(
子项:文本('Following'),
),
居中(
子:文本(“跟随者”),
),
ListView.builder(
物品计数:100,
项目范围:100.0,
项目生成器:(c,i){
返回中心(
子项:文本(i.toString())
);
},
)
]
),
)
],
)
),
);
但是由于扩展
控制台说
颤振:不正确使用ParentDataWidget
我试图将列
或Flex
包装起来,但这次控制台显示了这些
RenderFlex子项具有非零的弹性,但传入的高度约束是无界的
如何使整个页面可滚动?问题在于
TabBarView
的父级,如果使用Expanded
,它不知道需要扩展多少,因为ListView
没有约束
将展开的容器替换为固定高度的SizedBox
或Container
:
SizedBox(
height: 600.0,
child: TabBarView(
问题在于
选项卡视图
的父级,如果使用扩展
,它不知道需要扩展多少,因为列表视图
没有约束
将展开的容器替换为固定高度的SizedBox
或Container
:
SizedBox(
height: 600.0,
child: TabBarView(
我认为更优雅的解决方案是在
NestedScrollView
中使用Sliver
s
更多信息
我认为一个更优雅的解决方案是在
嵌套滚动视图中使用Sliver
s
更多信息
感谢您的帮助!成功了!但是没有固定的高度,有没有固定的方法呢?因为我想将ListView.builder的物理设置为NeverScrollableScrollPhysics,因为两个可滚动的ListView工作起来有点奇怪。您可以使用MediaQuery获取屏幕高度并使用这些值。感谢您的帮助!成功了!但是没有固定的高度,有没有固定的方法呢?因为我想将ListView.builder的物理设置为NeverScrollableScrollPhysics,因为两个可滚动的ListView工作起来有点奇怪。您可以使用MediaQuery获取屏幕高度并播放这些值。