【问题标题】:Error: Getter not found: 'widget'. widget.icon错误:找不到吸气剂:“小部件”。小部件.icon
【发布时间】:2021-08-19 12:20:09
【问题描述】:

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

错误显示在图像上方。 它发生在 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)),
           ),
         ],
       ),
     ),
   );
 }
}

我做错了吗?

【问题讨论】:

    标签: android flutter widget


    【解决方案1】:

    您必须从 ListTile 中删除 const

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2018-10-31
    • 2020-02-24
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多