根据应用栏“页面过滤器”的概念,我想将 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',
),
],
),
),
);
}
}
由于下划线看起来很奇怪,它不遵循上述链接中的 Material 模式......奖励:文本和按钮应该是白色的。
最佳答案
我确实找到了一些对我的情况有所帮助的东西... DropdownButtonHideUnderline
和 Theme
小部件将有助于控制下拉列表在 AppBar 标题中的外观
new AppBar(
title: new Theme(
child: new DropdownButtonHideUnderline(
child: new DropdownButton<String>(
value: _value,
items: <DropdownMenuItem<String>>[
new DropdownMenuItem(
child: new Text('My Page'),
value: 'one',
),
],
onChanged: (String value) {
setState(() => _value = value);
},
),
),
data: new ThemeData.dark(),
),
),
但是,现在弹出窗口的背景颜色为黑色以匹配深色主题...不确定是否有办法让主题不影响实际弹出窗口。
我个人可以忍受弹出窗口的黑色背景色......除非有人也能解决这个问题。
关于material-design - Flutter 自定义标题下拉菜单( Material 页面过滤器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49156899/