|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// There is a copy of the implementation of this mixin at widgets/dismissble.cs,
|
|
|
|
// There is a copy of the implementation of this mixin
|
|
|
|
KeepAliveHandle _keepAliveHandle; |
|
|
|
|
|
|
|
void _ensureKeepAlive() { |
|
|
|
D.assert(this._keepAliveHandle == null); |
|
|
|
this._keepAliveHandle = new KeepAliveHandle(); |
|
|
|
new KeepAliveNotification(this._keepAliveHandle).dispatch(this.context); |
|
|
|
} |
|
|
|
|
|
|
|
void _releaseKeepAlive() { |
|
|
|
this._keepAliveHandle.release(); |
|
|
|
this._keepAliveHandle = null; |
|
|
|
} |
|
|
|
|
|
|
|
protected abstract bool wantKeepAlive { get; } |
|
|
|
|
|
|
|
protected void updateKeepAlive() { |
|
|
|
if (this.wantKeepAlive) { |
|
|
|
if (this._keepAliveHandle == null) { |
|
|
|
this._ensureKeepAlive(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if (this._keepAliveHandle != null) { |
|
|
|
this._releaseKeepAlive(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void initState() { |
|
|
|
base.initState(); |
|
|
|
if (this.wantKeepAlive) { |
|
|
|
this._ensureKeepAlive(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void deactivate() { |
|
|
|
if (this._keepAliveHandle != null) { |
|
|
|
this._releaseKeepAlive(); |
|
|
|
} |
|
|
|
|
|
|
|
base.deactivate(); |
|
|
|
} |
|
|
|
|
|
|
|
public override Widget build(BuildContext context) { |
|
|
|
if (this.wantKeepAlive && this._keepAliveHandle == null) { |
|
|
|
this._ensureKeepAlive(); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public abstract class AutomaticKeepAliveClientWithTickerProviderStateMixin<T> : State<T>, TickerProvider |
|
|
|
where T : StatefulWidget { |
|
|
|
HashSet<Ticker> _tickers; |
|
|
|
|
|
|
|
public Ticker createTicker(TickerCallback onTick) { |
|
|
|
this._tickers = this._tickers ?? new HashSet<Ticker>(); |
|
|
|
var result = new _AutomaticWidgetTicker<T>(onTick, this, debugLabel: "created by " + this); |
|
|
|
this._tickers.Add(result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
internal void _removeTicker(_AutomaticWidgetTicker<T> ticker) { |
|
|
|
D.assert(this._tickers != null); |
|
|
|
D.assert(this._tickers.Contains(ticker)); |
|
|
|
this._tickers.Remove(ticker); |
|
|
|
} |
|
|
|
|
|
|
|
public override void dispose() { |
|
|
|
D.assert(() => { |
|
|
|
if (this._tickers != null) { |
|
|
|
foreach (Ticker ticker in this._tickers) { |
|
|
|
if (ticker.isActive) { |
|
|
|
throw new UIWidgetsError( |
|
|
|
this + " was disposed with an active Ticker.\n" + |
|
|
|
this.GetType() + |
|
|
|
" created a Ticker via its TickerProviderStateMixin, but at the time " + |
|
|
|
"dispose() was called on the mixin, that Ticker was still active. All Tickers must " + |
|
|
|
"be disposed before calling super.dispose(). Tickers used by AnimationControllers " + |
|
|
|
"should be disposed by calling dispose() on the AnimationController itself. " + |
|
|
|
"Otherwise, the ticker will leak.\n" + |
|
|
|
"The offending ticker was: " + ticker.toString(debugIncludeStack: true) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
}); |
|
|
|
base.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void didChangeDependencies() { |
|
|
|
bool muted = !TickerMode.of(this.context); |
|
|
|
if (this._tickers != null) { |
|
|
|
foreach (Ticker ticker in this._tickers) { |
|
|
|
ticker.muted = muted; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
base.didChangeDependencies(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|
|
|
base.debugFillProperties(properties); |
|
|
|
properties.add(new DiagnosticsProperty<HashSet<Ticker>>( |
|
|
|
"tickers", |
|
|
|
this._tickers, |
|
|
|
description: this._tickers != null ? "tracking " + this._tickers.Count + " tickers" : null, |
|
|
|
defaultValue: Diagnostics.kNullDefaultValue |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
KeepAliveHandle _keepAliveHandle; |
|
|
|
|
|
|
|
void _ensureKeepAlive() { |
|
|
|