我坚持如何解决这个问题。我想要实现的是使整个页面可滚动。因此,当您向下滚动时,页面的顶部将不可见,只有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())
);
},
)
]
),
)
],
)
),
);
但是因为Expanded
控制台说
颤动:使用ParentDataWidget不正确。
我试图包装Column
或Flex
,但这次控制台说
RenderFlex子项具有非零flex,但传入高度约束是无限制的。
如何使整个页面可滚动?
问题是你的TabBarView
的父母,如果你使用Expanded
,它不知道它将扩展多少,因为没有ListView
的限制。
用固定高度替换扩展的SizedBox
或Container
:
SizedBox(
height: 600.0,
child: TabBarView(
我认为一个更优雅的解决方案是在Sliver
中使用NestedScrollView
s
更多信息https://docs.flutter.io/flutter/widgets/NestedScrollView-class.html