【发布时间】:2020-10-15 17:19:39
【问题描述】:
我们使用抽屉来显示“设置”状态。我希望用户能够更改设置并查看抽屉中反映的结果。
但是当我调用 setState 时,它会更新父窗口,而不是 Drawer 状态。
我希望用户能够将通知从“无”更改为“电话”并查看抽屉状态中的反映。但它总是显示原始价值。
@override
Widget build(BuildContext context) {
var key = GlobalKey<ScaffoldState>();
return Scaffold(
key: key,
body: Text("Test Data"),
bottomNavigationBar: NavBar(),
drawer: Drawer( child: components( context ) ),
);
}
Widget components( context )
{
return ListView(
children: <Widget>[
ListTile( dense: true, leading: Icon(Icons.notifications), title: Text("Notifications"),
trailing: DropdownButtonHideUnderline ( child: DropdownButton<String>(
value: Settings.notifications.toString().split('.')[1],
icon: Icon(Icons.expand_more),
onChanged: (String newValue) {
if ( 'none' == newValue )
Settings.notifications = Notifications.none;
else if ( 'email' == newValue )
Settings.notifications = Notifications.email;
else if ( 'phone' == newValue )
Settings.notifications = Notifications.phone;
else
Settings.notifications = Notifications.both;
setState(() {
});
},
items: <String>['none','email','phone','both']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>( value: value, child: Text(value), );
}).toList(),
) ),),
],
);
}
【问题讨论】:
-
所以选择后你想更改默认文本?