Looking up a deactivated widget's ancestor is unsafe

前端 未结 5 2069
鱼传尺愫
鱼传尺愫 2020-12-29 03:46

I am new in Flutter and I am trying receive data with a Dialog. When a click in textField the error of image2 appear...

5条回答
  •  自闭症患者
    2020-12-29 04:07

    You’re trying to access a context that isn’t probably available. That happens because you’ve assigned your Dialog to a var and afterwards use a different context (the one from your dialog builder).

    Either create your dialog directly after your return in the builder or make it a method instead that returns a Dialog and pass it a BuildContext parameter.

    Widget myDialog(BuildContext context) => Dialog(/*your dialog here*/);
    

    This is also a more convenient Flutter practice. You should use methods that return widgets instead of assigning it to variables.

提交回复
热议问题