flutter始めたばかりで1時間ほどタイトルのエラーではまりました
とりあえず結論
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // ダメ Container( height: min(widget.order.products.length * 20.0 + 10, 180), child: ListView( children: widget.order.products.map((prod) => Row()), ), ), // OK // RowにtoList()メソッド入れる Container( height: min(widget.order.products.length * 20.0 + 10, 180), child: ListView( children: widget.order.products.map((prod) => Row()).toList(), ), ), |
なぜ発生していたか?
Rowのchildrenには、通常<Widget>[]
が入っており、Widget型のリストが期待されています。
しかしmapではRow
だけ返していて、List型に変換されていないことが問題でした。
なので、最後にtoList()
メソッドを入れてあげることで、<Widget>[]
に適した型となり、エラーを吐き出さないようになります。