【发布时间】:2018-08-15 20:23:13
【问题描述】:
按照应用栏“页面过滤器”的概念,我想将DropdownButton 作为AppBar 的标题。我试过了,但看起来不太好。
https://material.io/guidelines/layout/structure.html#structure-app-bar
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _value = 'one';
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new DropdownButton<String>(
value: _value,
items: <DropdownMenuItem<String>>[
new DropdownMenuItem(
child: new Text('one'),
value: 'one',
),
new DropdownMenuItem(
child: new Text('two'),
value: 'two'
),
],
onChanged: (String value) {
setState(() => _value = value);
},)
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
'hello world',
),
],
),
),
);
}
}
由于下划线看起来很奇怪,它不遵循上述链接中的材料模式......奖励:文本和按钮应该是白色的。
【问题讨论】:
-
> 不遵循上述链接中的材料模式,没有链接
-
而且我怀疑材料在 appbar 内有任何关于 DropDown 的规则;根据材料,appbar内只能使用字符串和图标。
-
@Darky 见上面的编辑(链接也在这里:material.io/guidelines/layout/structure.html#structure-app-bar)
-
在IOS上根据规范标题居中
-
@Darky 这非常没有帮助。我特别说,“忽略左右位置,因为它是在 iOS 中渲染的”