android - 错误:找不到吸气剂:“小部件”。小部件.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)),
),
],
),
),
);
}
}
我做错了什么吗?
解决方案
您必须const
从 ListTile 中删除。
推荐阅读
- huawei-mobile-services - 无法为华为 Map Kit 生成签名证书 sha 256
- variables - Jenkins:在 Shell 脚本/CURL 请求中使用变量
- php - Codeception – 无法设置
- shell - 使用awk解析html以获取两个div标签之间的内容
- python - 陷入二分搜索算法程序
- python - 奇怪的关机行为
- json - 集成 Hive 数据库
- clickhouse - 命令 clickhouse-backup create 不提供元数据文件夹和空的影子文件夹
- flutter - Flutter 将状态数据传递给函数
- r - lmer 错误:Hessian 在数值上是奇异的