我在名为"AddAnnouncementDialogWidgetState"
的类中有一个DropdownButton,我希望将所选值存储在AppState中,以便在其他类中使用它。
DropDownButton:
var _currentItemSelected;
var _templates = ['birth', 'wedding', 'holiday'];
...
DropdownButton<String>(
hint: Text("select a type"),
items: _templates.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(dropDownStringItem),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemSelected = newValueSelected;
});
},
value: _currentItemSelected,
),
与_currentItemSelected
一起包含所选项目。
AppState类:
class AppState {
static var empty = AppState(new List(),User('', ''));
final List<Announcement> announcements;
final User user;
AppState(this.announcements, this.user);
AppState.fromJson(Map<String, dynamic> json, this.user)
: announcements = (json['AnnouncementItem'] as List)
.map((i) => new Announcement.fromJson(i as Map<String, dynamic>))
.toList();
Map<String, dynamic> toJson() => {'announcements': announcements};
}
公告:
class Announcement {
String title;
String description;
int id;
String type;
Announcement(this.title, this.description, this.type);
Announcement.fromJson(Map<String, dynamic> json): title = json['title'], description = json['description'];
Map<String, dynamic> toJson() => {'title': title, 'description': description};
@override
String toString() {
return "$title: $description";
}
}
我想将所选的礼炮存储在“ type”参数中。
有人对如何做有任何想法吗?