【问题标题】:I am not able to use the variables我无法使用变量
【发布时间】:2022-11-24 15:39:24
【问题描述】:

我无法使用变量

我只想在文本小部件的另一个页面中使用这些变量,但我不能通过

【问题讨论】:

  • 你可以添加你的代码而不是屏幕截图吗?

标签: flutter


【解决方案1】:

您必须将 _tabs 变量分配到其他地方。我不能说在哪里,因为你没有提供足够的代码(你应该将代码作为文本而不是图像)。但它是例如在构造函数或initState 方法中。

这是不允许的:

class Foo {
  Foo(this.bar);
  final String bar;
  final List<String> baz = [bar];
}

做(例如)像这样:

class Foo {
  Foo(this.bar) {
    baz = [bar];
  }
  final String bar;
  late final List<String> baz;
}

【讨论】:

    【解决方案2】:

    一个简单的解决方案是简单地将您的_tabs标记为late,就像

    late final List<Widget> _tabs = [
    

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2018-06-10
      • 2017-06-22
      • 2012-11-19
      相关资源
      最近更新 更多