在运行dart migrate并应用 null 安全性之后,我的代码中弹出了该错误,我认为这是导致代码块的错误。
LayoutBuilder(builder: (context, cons) {
return GestureDetector(
child: new Stack(
children: <Widget?>[
// list of different widgets
.
.
.
].where((child) => child != null).toList(growable: true) as List<Widget>,
),
);
),
错误消息说:
The following _CastError was thrown building LayoutBuilder:
type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast
The relevant error-causing widget was
LayoutBuilder
package:projectName/…/components/fileName.dart:182
如果有人遇到这个问题,如何解决?