上下文实例的波动范围

时间:2019-03-30 12:11:38

标签: dart flutter

参考官方Flutter tutorialcontext_pushSaved()函数?

class RandomWordsState extends State<RandomWords> {
  ...
  void _pushSaved() {
    Navigator.of(context).push(
      ...
    );
  }
}

1 个答案:

答案 0 :(得分:0)

引用Flutter文档:https://api.flutter.dev/flutter/widgets/State-class.html

State类具有context属性,它是BuildContext的实例

因此,您可以在扩展State类的RandomWordsState类中引用context