【问题标题】:Navigator push need key?导航推需要钥匙吗?
【发布时间】:2021-03-12 00:18:31
【问题描述】:

在升级之前,这段代码可以正常工作: code now with and error

现在这不起作用并出现此错误: eror description

代码如下: code1 code2 请帮忙。

【问题讨论】:

  • 你能给你的产品代码截图吗?
  • 全部119行代码?不是很漂亮,但是如果您要求错误,那么当我尝试使用 navigator push @Adithaz 时也会出现同样的错误
  • 我认为顶部的 50 个代码很好
  • 我编辑询问@Adithaz
  • 请了解如何在您的帖子中嵌入代码,而不是提供屏幕截图。

标签: flutter


【解决方案1】:
class Productos extends StatefulWidget {
   //You can delete this line below and the problem will be solved
   Productos({required Key key}) : super(key: key); //<--this line

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

但是,在你删除它之前,如果你需要这条线,请再检查一次。在 productos.dart 上按 ctrl + f 并搜索“widget.key”。如果没有,您可以安全地删除该行。

【讨论】:

    【解决方案2】:

    不,导航器不需要钥匙。但是在 Productos 类构造函数中查看您的 productos.dart,您有一个“必需”关键字

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 2010-10-21
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多