解决重写 initState 方法引发的警告错误

302 阅读1分钟

在重写 initState 方法时,不主动调用父类的 initState 方法会报出警告错误

void initState() {
    //监听输入改变
    _textController.addListener(() {
      print(_textController.text);
    });
}

警告错误信息:

\color{red}{info: This\ method\ overrides\ a\ method\ annotated\ as\ @mustCallSuper\ in\ 'State',\ but\ does\ not\ invoke\ the\ overridden\ method.}

解决方法

void initState() {
    super.initState();
    //监听输入改变
    _textController.addListener(() {
      print(_textController.text);
    });
}

随手笔记,感谢阅读,不对之处请指教,谢谢!