分离生命周期后flutter setState不起作用

时间:2020-08-06 15:03:10

标签: flutter flutter-add-to-app

我的flutter项目是使用添加到现有的应用程序

我只想在活动销毁时处置小部件

我的statefulWidget中的示例是这样的

  final GlobalKey<OverlayState> _overlayKey = GlobalKey<OverlayState>();
  OverlayEntry current;

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.detached) {
      pop();
    }
  }

 @override
  Widget build(BuildContext context) {
    return Overlay(
      key: _overlayKey,
      initialEntries: const <OverlayEntry>[],
    );
  }

  void pop() {
    current.remove();
    setState(() {});
  }

  void push(OverlayEntry app) {
    assert(app != null);
    
    setState(() {
      current = app;
      overlayKey.currentState.insert(app);
      _overlayKey.currentState.setState(() {

      });
    });
  }

在分离生命周期事件之后,OverlayEntry中的statefulWidget似乎没有调用dispose方法

活动开始后它才有用吗,有人帮我吗?

0 个答案:

没有答案