flutter 如何使整个页面可滚动?
flutter how can I make this whole page scrollable?
我不知道如何解决这个问题。
我想要实现的是使整个页面可滚动。
因此,当您向下滚动时,页面的顶部将不可见,只有 TabBarView
可见。
我有这个 code.
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())
);
},
)
]
),
)
],
)
),
);
但是因为 Expanded
控制台说
flutter: Incorrect use of ParentDataWidget.
我尝试包装 Column
或 Flex
但这次控制台说的是
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
如何使整个页面可滚动?
问题出在您的 TabBarView
的父级上,如果您使用 Expanded
,它不知道需要扩展多少,因为 ListView
没有限制.
用固定高度替换 SizedBox
或 Container
的扩展:
SizedBox(
height: 600.0,
child: TabBarView(
我认为更优雅的解决方案是在 NestedScrollView
中使用 Sliver
s
更多信息
https://docs.flutter.io/flutter/widgets/NestedScrollView-class.html
我不知道如何解决这个问题。
我想要实现的是使整个页面可滚动。
因此,当您向下滚动时,页面的顶部将不可见,只有 TabBarView
可见。
我有这个 code.
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())
);
},
)
]
),
)
],
)
),
);
但是因为 Expanded
控制台说
flutter: Incorrect use of ParentDataWidget.
我尝试包装 Column
或 Flex
但这次控制台说的是
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
如何使整个页面可滚动?
问题出在您的 TabBarView
的父级上,如果您使用 Expanded
,它不知道需要扩展多少,因为 ListView
没有限制.
用固定高度替换 SizedBox
或 Container
的扩展:
SizedBox(
height: 600.0,
child: TabBarView(
我认为更优雅的解决方案是在 NestedScrollView
Sliver
s
更多信息 https://docs.flutter.io/flutter/widgets/NestedScrollView-class.html