Forms 当移动到另一个屏幕时,如何使下拉列表保持最后选择的选项在颤振中
我的颤振应用程序中有这些过滤器 我需要一种方法来保留最后选择的选项 这是我的ddl代码Forms 当移动到另一个屏幕时,如何使下拉列表保持最后选择的选项在颤振中,forms,flutter,dart,drop-down-menu,Forms,Flutter,Dart,Drop Down Menu,我的颤振应用程序中有这些过滤器 我需要一种方法来保留最后选择的选项 这是我的ddl代码 DropdownButton<String>( isExpanded: true, value: selectedValue, icon: Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, style: TextStyle(color:
DropdownButton<String>(
isExpanded: true,
value: selectedValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.black),
underline: Container(
height: 2,
color: Colors.black,
),
onChanged: (String newValue) {
setState(() {
selectedValue = newValue;
});
widget.onSelect(newValue);
},
items: _getList(this.widget.name),
),
下拉按钮(
是的,
值:selectedValue,
图标:图标(图标。向下箭头),
iconSize:24,
海拔:16,
样式:TextStyle(颜色:Colors.black),
下划线:容器(
身高:2,
颜色:颜色,黑色,
),
onChanged:(字符串newValue){
设置状态(){
selectedValue=newValue;
});
onSelect(newValue);
},
项目:_getList(this.widget.name),
),
跨屏幕保留值的一种方法是将它们保留在一个带有getter和setter的静态变量的类中。每次下拉值更改时,您也会设置此静态变量。在屏幕加载时,您将读取这些值并初始化小部件
class dropDownModel {
static int last_selected_value;
static int get_last_selected_value() {
return last_selected_value;
}
static void set_last_selected_value(int Value) {
last_selected_value = Value;
return null;
}
}
你的意思是这样的``initialValue:DropDownModel.getLastSelectedValue(),onSelect:(str){setState(){DropDownModel.setLastSelectedValue(str);)``它不起作用
class dropDownModel {
static int last_selected_value;
static int get_last_selected_value() {
return last_selected_value;
}
static void set_last_selected_value(int Value) {
last_selected_value = Value;
return null;
}
}