flutter - 如何在单击按钮2时更改按钮1的背景颜色,反之亦然
问题描述
要求:我有两个按钮,一个是时间进入,另一个是超时。
启用时间的条件是
t2 != "" || t1 == ""
和超时启用条件是
t1 != ""
时间将被禁用时
t1 != "" && t2==""
并且超时将被禁用
t1==""
当我单击按钮时,其文本应更改为当前时间。
问题:一切都在一次正常工作,就像最初启用按钮的时间和禁用超时按钮一样,当我单击按钮中的时间时,它的文本和背景颜色会发生变化,而超时按钮会启用它的背景颜色也会发生变化,但是当我单击超时按钮时,它的文本会更改但按钮中的时间未启用,它仍然处于禁用状态,我想让它启用并且它的颜色应该改变并且与超时按钮相同,总之它应该执行反之亦然.
这是我所做的
var timeInText=" Time in";
var timeOutText=" Time out";
bool timeInBttonPressed=false;
bool timeOutButtonPressed=false;
var t1="";
var t2="";
void initState() {
// TODO: implement initState
super.initState();
_getTime();
}
Widget _timein() {
//enable
if(t2 != "" || t1 == "" ) {
return RoundedButton(icon: Icon(Icons.timer,color: Colors.white),
text:timeInText,
bgcolor: timeInBttonPressed ?Colors.blue[200]:Colors.blue[500],
press: () {
_getTime();
setState(() {
timeInText=" "+getTime;
t1=getTime;
print("t1 "+t1);
timeInBttonPressed=true;
});
});
}
//disable
else if(t1 != "" && t2=="") {
return RoundedButton(icon: Icon(Icons.timer,color: Colors.white),
text:timeInText,
bgcolor: Colors.blue[200],
);
}
}
Widget _timeout(){
//enable
if(t1 != "") {
return RoundedButton(icon: Icon(Icons.timer,color: Colors.white),
text:timeOutText,
bgcolor: timeOutButtonPressed ?Colors.blue[200]:Colors.blue[500],
press: () {
_getTime();
setState(() {
timeOutText=" "+getTime;
//t2=getTime;
print("t2 "+t2);
//timeOutButtonPressed=true;
timeInBttonPressed=true;
});
});
}
//disable
else if(t1== "") {
return RoundedButton(icon: Icon(Icons.timer,color: Colors.white),
text:timeOutText,
bgcolor: Colors.blue[200]);
}
}
void _getTime() {
final String formattedDateTime =
DateFormat('kk:mm:ss').format(DateTime.now()).toString();
setState(() {
getTime = formattedDateTime;
print(getTime[0]);
});
}
注意:它基本上是一个考勤系统,其中用户登录时应该先做时间,当时间完成后才能超时。如果用户想再次计时,那么他可以,然后他必须在第二天再次计时。
希望一切都清楚,请帮助我解决我的问题。会非常感谢你。
解决方案
推荐阅读
- c# - 如何在接口的空列表中获取对象类型
- zebra-printers - Zebra LP2844 不会打印 EPL2 命令(页面模式),只有 EPL1(行模式)有效
- splunk - 使用 Lookup 从单个字段 CSV 文件中进行搜索
- vim - 如何让谷歌云外壳在 vim 中正确识别 Esc 键
- laravel - 在 laravel 中访问数据
- python - Python 相对路径导入:从另一个项目目录导入包
- google-docs-api - Google 趋势数据中使用的时区是什么?
- sqlite - 带有 React Native 错误的 SQLite 'table xxxx has no column yyyy'
- html - Vue输入下拉简单
- php - date_default_timezone_set() 损坏的时区