问题出现在 Text(textToDisplay)
我得到了错误Arguments of a constant creation must be constant expressions.
class IconText extends StatelessWidget {
const IconText({super.key, required this.icon, required this.textToDisplay});
final IconData icon;
final String textToDisplay;
@override
Widget build(BuildContext context) {
return const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.male,
size: 80,
color: Colors.grey,
),
SizedBox(height: 15),
Text(textToDisplay)
],
);
}
}
我像这样使用这个小部件
const Expanded(
child: Row(
children: [
NewWidget(
color: widgetColor,
cardChild: IconText(icon: Icons.male, textToDisplay: "Male"),
),
NewWidget(
color: widgetColor,
cardChild: IconText(icon: Icons.male, textToDisplay: "Female"),
)
],
)),
我该如何修复这个错误?
您必须删除列的const