I've got this problem while trying the below code.
In order to fix this issue, I have changed it as shown below.
Thanks,
class MyWidget extends StatelessWidget {
const MyWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: Wrap(
spacing: 10.0,
alignment: WrapAlignment.start,
children: [
const MyContainer(), //Error occured in this line
const MyContainer(), //Error occured in this line
const MyContainer(), //Error occured in this line
],
),
);
}
}
First of all this is not an error, and your program should work fine without resolving it too. But, no one likes to see some squiggly lines in their programs, right?
However, the reason it occurred, is that all the widgets inside the List are immutable. Hence it suggests adding the const keyword in one place.
class MyWidget extends StatelessWidget {
const MyWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: Wrap(
spacing: 10.0,
alignment: WrapAlignment.start,
children: const [
MyContainer(),
MyContainer(),
MyContainer(),
],
),
);
}
}
Hope this is helpful.
Srikanth