Warm tip: This article is reproduced from serverfault.com, please click

flutter-创建TextEditingController对象时发生错误

(flutter - An error occurs when creating TextEditingController object)

发布于 2020-11-28 01:08:52

我有一个问题,如下所示,创建对象时发生错误。

前任)

  final TextEditingController = TextEditingController();

错误消息是这样的:

Only static members can be accessed in initializers.

我对这个错误的原因以及解决方法感到好奇

谢谢你让我知道〜!

错误消息捕获

Questioner
hyun k
Viewed
0
kovalyovi 2020-11-28 10:27:39

你在这里的错误是你忘记命名变量了。你定义了它final的类型TextEditingController,但未命名变量。在你的情况下,修复会(只是变量名建议:_controller

final TextEditingController _controller = TextEditingController();