コード例 #1
0
        public override void didChangeDependencies()
        {
            base.didChangeDependencies();
            if (widget.onWillPop != null)
            {
                _route?.removeScopedWillPopCallback(widget.onWillPop);
            }

            _route = ModalRoute.of(context);
            if (widget.onWillPop != null)
            {
                _route?.addScopedWillPopCallback(widget.onWillPop);
            }
        }
コード例 #2
0
        public override void didUpdateWidget(StatefulWidget _oldWidget)
        {
            base.didUpdateWidget(_oldWidget);
            D.assert(_route == ModalRoute.of(context));
            WillPopScope oldWidget = _oldWidget as WillPopScope;

            if (widget.onWillPop != oldWidget.onWillPop && _route != null)
            {
                if (oldWidget.onWillPop != null)
                {
                    _route.removeScopedWillPopCallback(oldWidget.onWillPop);
                }

                if (widget.onWillPop != null)
                {
                    _route.addScopedWillPopCallback(widget.onWillPop);
                }
            }
        }