【问题标题】:Undefined name 'title'. (Documentation)未定义名称“标题”。 (文档)
【发布时间】:2023-01-11 17:54:20
【问题描述】:

嗨,我是新手,面临以下错误

final String title;
final String desc;
final String timer;
const ListElement({Key? key, required this.title, required this.desc ,required this.timer}) : 
super(key: key);

这是我的构造函数,我在其中传递了 title desc 和 timer

 Text(title, style: TextStyle(fontWeight: FontWeight.w400 ,
                  fontSize: 30),),
 Text(desc, style: TextStyle(fontWeight: FontWeight.w400 ,
                  fontSize: 15),),

在获取 title 和 desc 时我遇到了这个错误

【问题讨论】:

  • 你能为 ui 和模型类提取正确的代码吗?
  • 谢谢我解决了我的问题
  • 请复习答案
  • 你接受我的回答吗? @赫克托4888

标签: android flutter dart


【解决方案1】:

如果您的小部件是stateful,那么您必须将title写为

Text(widget.title, style: .......

【讨论】:

    【解决方案2】:

    好的,我使用 '${widget.title}' 来解决这个问题

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2020-06-27
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-25
      • 1970-01-01
      • 2016-05-20
      相关资源
      最近更新 更多