Error: Getter not found: 'widget'. widget.icon

Error: Getter not found: 'widget'. widget.icon

我正在创建一个包含图标和文本的卡片组件作为儿童小部件。 我初始化了这些图标并想在其子窗口小部件中使用它们,但它给出了错误

图片上方显示了错误。 它发生在 widget.icon、widget.title,如果我在 widget.subtitle 上使用它也会发生。下面是完整代码

import 'package:flutter/rendering.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:api_example_app/constants.dart';
import 'package:flutter/widgets.dart';

class CardsParent extends StatefulWidget {
 const CardsParent({
   Key key,
   @required this.size,
   this.icon,
   this.title,
   this.subtitle,
 }) : super(key: key);

 final Size size;
 final IconData icon;
 final String title;
 final String subtitle;

 @override
 _CardsParentState createState() => _CardsParentState();
}

class _CardsParentState extends State<CardsParent> {
 @override
 Widget build(BuildContext context) {
   return Container(
     width: 140,
     height: 100,
     child: Card(
       shape: RoundedRectangleBorder(
         borderRadius: BorderRadius.circular(15.0),
       ),
       color: Colors.white,
       elevation: 10,
       child: Column(
         mainAxisSize: MainAxisSize.min,
         children: <Widget>[
           const ListTile(
             leading: Icon(
               widget.icon,
               size: 50,
               color: kOrangeColor,
             ),
             title: Text('Temp',
                 style: TextStyle(fontSize: 18.0, color: kOrangeColor)),
             subtitle: Text('33C', style: TextStyle(color: kOrangeColor)),
           ),
         ],
       ),
     ),
   );
 }
}

我是不是做错了什么?

您必须从 ListTile 中删除 const