flutter - 如何根据 Flutter 中的条件启用/禁用 DropDownButton?
问题描述
我是 Flutter 的新手,我正在制作休假申请,因为我创建了两个 DropdownButton。在From Date Half Leave:的一个 DropdownButton 和To Date Half Leave的第二个DropdownButton 中。我在两个下拉按钮中都显示了相同的项目列表。问题是,当我从From Date Half Leave中选择相同的项目时,它不应该在第二个 DropdownButton 中隐藏相同的选项,这意味着在To Date Half Leave中。
例如,如果From date和To date 相同,那么我想在两个下拉按钮中显示选项,但是当用户从From Date Half Leave中选择一个项目时,它会隐藏To Date Half Leave中的项目选项。如果从日期和到日期不同,那么它在从日期半假和到日期半假中显示相反的选项,例如从日期半假选择早上然后在截止日期半假中我不显示早上选项它只显示下午选项如果开始日期半假和截止日期半假只有那么不同。我不能这样做所以请帮助我..
我的代码如下:我只是尝试禁用To Date Half Leave的项目,当From Date和To Date相同时,当用户选择From Date Half Leave下拉按钮项目时,它禁用To Date Half Leave中的项目。
var _days = ['早上', '下午',];
Padding(
padding: const EdgeInsets.only(top:8.0),
child: Row(
children: <Widget>[
Container(
//width: 200.0,
child: Text('From Date :',
style: Theme.of(context).textTheme.subtitle2.copyWith(color: Colors.black),
),
),
]
),
),
Container(
child: Column(
children: <Widget>[
ListTile(
trailing: Icon(Icons.calendar_today),
title: Text('$_formdate'),
contentPadding: EdgeInsets.only(left:4.0,right:0.0,),
enabled: true,
onTap: (){
_chooseDate(context);
}
),
],
),
),
Padding(
padding: const EdgeInsets.only(top:8.0),
child: Row(
children: <Widget>[
Container(
child: Text('To Date :',
style: Theme.of(context).textTheme.subtitle2.copyWith(color: Colors.black),
),
),
]
),
),
Container(
child: Column(
children: <Widget>[
ListTile(
trailing: Icon(Icons.calendar_today),
title: Text('$_todate'),
contentPadding: EdgeInsets.only(left:4.0,right:0.0,),
enabled: true,
onTap: (){
_chooseData2(context);
}
),
],
),
),
Padding(
padding: const EdgeInsets.only(top:8.0),
child: Row(
children: <Widget>[
Container(
child: Text('From Date Half leave :',
style: Theme.of(context).textTheme.subtitle2.copyWith(color: Colors.black),
),
),
]
),
),
new DropdownButton<String>(
dropdownColor: Colors.grey[300],
value: currentFDHLvalue,
isExpanded: true,
items: _days.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
underline: Container(
height: 1,
color: Colors.black26,
),
onChanged: (newValue) {
if (_formdate == _todate && currentFDHLvalue != null) {
setState(() { });
} else{
setState((){
currentTDHLvalue;
disabledItems = false;
});
}
setState(() {
currentFDHLvalue = newValue;
});
},
) ,
Padding(
padding: const EdgeInsets.only(top:8.0),
child: Row(
hildren: <Widget>[
Container(
child: Text('To Date Half leave :',
style: Theme.of(context).textTheme.subtitle2.copyWith(color: Colors.black),
),
),
]
),
),
new DropdownButton<String>(
dropdownColor: Colors.grey[300],
value: currentTDHLvalue,
isExpanded: true,
elevation: 22,
items: _days.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value,
style: TextStyle(
color: !disabledItems ? Colors.grey : null,
)
),
);
}).toList(),
underline: Container(
height: 1,
color: Colors.black26,
),
onChanged: (newValue) {
if (!disabledItems ? _formdate != _todate : currentTDHLvalue != newValue ) {
setState(() {
currentTDHLvalue = newValue;
disabledItems = false;
});
}
setState(() {
currentTDHLvalue = newValue;
});
},
) ,
解决方案
推荐阅读
- java - 如何使用 Maven 自动化多个构建?
- php - 使用 MYSQL 从 Prestashop 中的订单 ID 获取详细的产品列表
- html - Webapp 布局取决于设备
- coldfusion - 在链接回页面时重新显示数据库结果
- ssl - Coldfusion 2016 websockets SSL 连接失败
- git - 如何恢复从远程和本地存储库中删除的文件,以及如何防止将来丢失?
- python - 测试完成后打开 HtmlTestRunner 报告
- excel - 计算数据集和另一列中特定标准的公式
- node.js - 设置后无法发送标头
- java - 在java中使用Enum来存储一组固定的可变对象