TextField
のクリアボタンを以下のようにしたが、
decoration: InputDecoration( // クリアボタンはオンオフ表示 suffixIcon: (ref.watch(_textProvider) != '') ? IconButton( onPressed: () { textEditingController.clear(); ref .read(_textProvider.notifier) .state = ''; }, icon: const Icon( Icons.clear, ), ) // 非表示 : null,
長い。 使わない時はnull入れるとなぜかサイズが変わってしまう・・・。
: null,
の代わりに
// 非表示の時のダミー : IconButton( iconSize: 0, onPressed: () {}, icon: const SizedBox(), ),
しかしこれだとコードが長い。
使わない時はアイコンを Colors.transparent
の色にするのが良さそう。
icon: const Icon( Icons.clear, color: Colors.transparent, ),
これなら押されても何も発生しない。