Flutterにて『The argument type ‘IconData’ can’t be assigned to the parameter type ‘Widget’.』が出た時の解決法

Flutter
 

環境

macOS Big Sur Version 11.5.2

Flutter 2.2.3

XCode 12.5.1

問題

The argument type 'IconData' can't be assigned to the parameter type 'Widget'.
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          IconButton(
            onPressed: onPressed,
            icon: Icons.access_alarm,
          )
        ],
        title: Text('Hello Todo'),
      ),
    );
  }

解決方法

IconData型をIcon型にWidget型に変換できるようにラップしてあげる必要がある。

icon: Icon(Icons.access_alarm),

コメント

タイトルとURLをコピーしました