Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何禁用按钮本身_Flutter_Dart - Fatal编程技术网

Flutter 如何禁用按钮本身

Flutter 如何禁用按钮本身,flutter,dart,Flutter,Dart,当app start button为enable时,我无法在其自身功能中禁用该按钮,当我单击该按钮时,_enable1=true,该按钮应为disable,但对我无效 这是我试过的代码 if(_enable1) { resendbutoonfunction=() { print("hello"); setState(() { _enable1=false; mycolo=Colors.grey; }); // tim

当app start button为enable时,我无法在其自身功能中禁用该按钮,当我单击该按钮时,_enable1=true,该按钮应为disable,但对我无效

这是我试过的代码

 if(_enable1) {
  resendbutoonfunction=() {
    print("hello");
    setState(() {
      _enable1=false;
      mycolo=Colors.grey;
    });
  //  timer = Timer.periodic(Duration(seconds: 5), (Timer t) =>disable());
   // _controller.forward(from: 0.0);
  //  timer = Timer.periodic(Duration(seconds: 4), (Timer t) =>timertest());
  };
}
这是我的按钮代码

onPressed:resendbutoonfunction,

据我所知,在编写代码时,测试(if_enable1)以及函数的定义只执行一次

测试必须位于函数内部:

resendbutoonfunction=() {
 if (_enable1) {
    ...
 }
}
或者,如果代码定期执行,则可以更改resendbutoonfunction的定义

if(_enable1) {
  resendbutoonfunction=() {
    print("hello");
    setState(() {
      _enable1=false;
      mycolo=Colors.grey;
    });
  //  timer = Timer.periodic(Duration(seconds: 5), (Timer t) =>disable());
   // _controller.forward(from: 0.0);
  //  timer = Timer.periodic(Duration(seconds: 4), (Timer t) =>timertest());
  };
}
else {
  resendbutoonfunction=() {
     // do nothing
  }
}
要禁用按钮,需要将其设置为null

然后,对于您的按钮:

onPressed: _enable1 ? resendbutoonfunction : null,
onPressed: _enable1 ? resendbutoonfunction : null,