退出Flutter应用程序后,我之前进入的页面保持打开状态[关闭]

问题描述 投票:0回答:0

退出 Flutter 应用程序后,我之前进入的页面仍然打开。 注销时,我写了如下代码

Navigator.pushAndRemoveUntil<dynamic>(
    context,
    MaterialPageRoute<dynamic>(
      builder: (BuildContext context) => RestartWidget(child: MainSecure()),
    ),
    (route) => false, //if you want to disable back feature set to false
  );

重启小工具

class RestartWidget extends StatefulWidget {
  RestartWidget({required this.child});

  final Widget child;

  static void restartApp(BuildContext context) {
    context.findAncestorStateOfType<_RestartWidgetState>()?.restartApp();
  }

  @override
  _RestartWidgetState createState() => _RestartWidgetState();
}
class _RestartWidgetState extends State<RestartWidget> {
  Key key = UniqueKey();

  void restartApp() {
    setState(() {
      key = UniqueKey();
    });
  }

  @override
  Widget build(BuildContext context) {
    return KeyedSubtree(
      key: key,
      child: widget.child,
    );
  }
}

但是,我之前打开的页面出现错误。 你怎么解决这个问题? 退出应用程序后我应该怎么做才能再次登录时没有问题?

flutter logout
© www.soinside.com 2019 - 2024. All rights reserved.