在此代码中:
class _MenuWidget extends StatelessWidget {
const _MenuWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
width: double.infinity,
child: const Column(children: [
_MenuWidgetRow(icon: Icons.computer),
_MenuWidgetRow(icon: Icons.computer),
_MenuWidgetRow(icon: Icons.computer),
_MenuWidgetRow(icon: Icons.computer),
],)
);
}
}
class _MenuWidgetRow extends StatelessWidget {
final IconData icon;
const _MenuWidgetRow({super.key, required this.icon});
@override
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Row(
children: [
Icon(icon), // Ошибка тут
SizedBox(width: 15),
Expanded(child: Text('test')),
Icon(Icons.chevron_right),
],
),
);
}
}
出现错误:
Arguments of a constant creation must be constant expressions.
Try making the argument a valid constant, or use 'new' to call the
constructor.dartconst_with_non_constant_argument
这和什么有关系呢?将绿色的推向解决方案:)