我正在尝试使用CupertinoSegmentedControl
中抖动的 Cupertino库中的AppBar
,并使用bottom属性来实现以下设计(高度= 32)
所以我尝试了以下方法:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 2,
backgroundColor: Colors.white,
centerTitle: true,
title: Text(this.widget.title, style: TextStyle(color: Colors.black)),
bottom: PreferredSize(
child: Padding(
padding: const EdgeInsets.only(top: 8, bottom: 12),
child: Row(
children: <Widget>[
SizedBox(width: 24),
Expanded(
child: CupertinoSegmentedControl(
children: this.widget.tabs,
groupValue: this._selectedTab,
onValueChanged: (value) {
this.setState(() => this._selectedTab = value);
this._tabController.animateTo(value);
}
),
),
SizedBox(width: 24)
],
),
),
preferredSize: Size(double.infinity, 48)
)
),
body: new TabBarView(
controller: this._tabController,
children: this.widget.views,
));
}
答案 0 :(得分:3)
类似于您想要的布局吗? (删除课程^ _ ^的绿色)
使用Container
和PreferredSize
高度来调整高度以适合您的需求。
Scaffold(
appBar: AppBar(
elevation: 2,
backgroundColor: Colors.white,
centerTitle: true,
title:
Text(this.widget.title, style: TextStyle(color: Colors.black)),
bottom: PreferredSize(
child: Row(
children: [
Expanded(
child: Container(
height: 48,
color: Colors.lightGreenAccent,
child: CupertinoSegmentedControl(
children: children,
groupValue: this._selectedTab,
onValueChanged: (value) {
this.setState(() => this._selectedTab = value);
}),
),
)
],
),
preferredSize: Size(double.infinity, 48))),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('hello')
]
)
)
);
答案 1 :(得分:0)
只需向容器中添加Padding小部件或margin属性,然后将其包装在“ tabs”集合中(如果您使用的是this.widget.tabs)
就我而言
CupertinoSegmentedControl<int>(
children: segmentTextWidgets,
...
),
final Map<int, Widget> segmentTextWidgets = <int, Widget>{
0: Container(
margin: const EdgeInsets.symmetric(vertical: 16),
child: Text("Tab 1 title"),
),
1: Container(
margin: const EdgeInsets.symmetric(vertical: 16),
child: Text("Tab 2 title"),
),
};