【发布时间】:2020-04-10 04:06:51
【问题描述】:
我有以下构建方法
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: size.getSizePx(277),
floating: false,
title: const Text("Details"),
pinned: true,
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Constants.gradientStart,
Constants.gradientEnd
]),
),
child: FlexibleSpaceBar(
centerTitle: true,
background: Image.asset(
"path/to/image",
fit: BoxFit.fill,
),
),
),
),
];
},
body: DefaultTabController(
length: 4,
child: SingleChildScrollView(
padding: EdgeInsets.only(
left: 7, right: 7),
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 180,
child: someTextWidgets(), //some widgets here
),
Expanded(
child: Container(
margin: EdgeInsets.only(top: 20),
child: _tabBarView(), // this will render tab bar and its contents
),
),
Container(
height: 10,
child: otherWidgets(), //other widgets here
),
],
),
),
),
)),
);
}
还有_tabBarView() 小部件
Widget _tabBarView() {
return Column(
children: <Widget>[
Container(
constraints: BoxConstraints.expand(height: 60),
child: TabBar(
labelStyle: TextStyle(fontSize: size.getSizePx(12)),
labelColor: Constants.primaryColor,
unselectedLabelColor: Colors.black45,
indicatorColor: Constants.primaryColor,
tabs: [
Tab(
text: "Contact Info",
icon: Icon(Constants.iconAccount),
),
Tab(
text: "Details",
icon: Icon(Constants.iconDetails),
),
Tab(
text: "Map",
icon: Icon(Constants.iconMap),
),
]),
),
Expanded(
child: Container(
child: TabBarView(children: [
Container(
margin: EdgeInsets.only(top: size.getSizePx(15)),
child: Column(
children: <Widget>[
//some text widgets here
],
),
),
Container(
margin: EdgeInsets.only(top: size.getSizePx(15)),
child: Column(
children: <Widget>[
//SOME TEXT WIDGETS,
//EPANSION TILES (ACCORDIONS)
],
),
),
Container(
margin: EdgeInsets.only(top: size.getSizePx(15)),
child: Text("Some long text here"),
),
]),
),
)
],
);
}
问题
如上面的 sn-p 代码所示,SingleChildScrollView 是 DefaultController 的子级,SingleChildScrollView 包含所有其他小部件。
第二个标签有很少的扩展图块,可以展开和折叠以显示/隐藏内容,当它展开时会显示bottom overflow by 消息。
如果选项卡中的内容大小增加,我需要整个页面可滚动。
我是 Flutter 的新手,有人可以帮我解决这个问题吗?
谢谢
【问题讨论】:
标签: flutter dart flutter-layout