Flutter アイコンボタンを無効にするかどうかを判断するサンプル

環境
Windows11 pro 64bit
Flutter 3.3.7

構文
onPressed: _isDisabled ? null : () {},
アイコンボタンを無効にするかどうかを判断させたい場合は、三項演算子を使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
IconButton(
onPressed: _isDisabled ? null : () {},
icon: Icon(Icons.add_a_photo),
)
IconButton( onPressed: _isDisabled ? null : () {}, icon: Icon(Icons.add_a_photo), )
IconButton(
  onPressed: _isDisabled ? null : () {},
  icon: Icon(Icons.add_a_photo),
)

 

Flutter

Posted by arkgame