Add Supa account and search changes
This commit is contained in:
@@ -19,31 +19,47 @@
|
||||
*/
|
||||
import 'dart:ui';
|
||||
|
||||
/// A wrapper around [Image] that compares by a precomputed byte-hash.
|
||||
///
|
||||
/// Instances are byte-hash deduped via the decoder's LRU, so the same
|
||||
/// `EquatableImage` may be shared across many holders (multiple tabs of
|
||||
/// the same site, the icon cache, widget closures). To make that safe,
|
||||
/// the underlying `ui.Image` is disposed via a [Finalizer] when this
|
||||
/// wrapper becomes unreachable — never on cache eviction or state
|
||||
/// transitions, where another holder might still be using it.
|
||||
class EquatableImage {
|
||||
static final Finalizer<Image> _finalizer = Finalizer<Image>(
|
||||
(image) => image.dispose(),
|
||||
);
|
||||
|
||||
Image? _value;
|
||||
final int _imageHash;
|
||||
bool _isDisposed = false;
|
||||
|
||||
EquatableImage(Image value, {required int hash})
|
||||
: _value = value,
|
||||
_imageHash = hash;
|
||||
_imageHash = hash {
|
||||
_finalizer.attach(this, value, detach: this);
|
||||
}
|
||||
|
||||
/// The underlying ui.Image. Returns null if disposed.
|
||||
/// The underlying ui.Image. Returns null if explicitly disposed.
|
||||
Image? get value => _isDisposed ? null : _value;
|
||||
|
||||
/// Whether this image has been disposed.
|
||||
/// Whether this image has been explicitly disposed.
|
||||
bool get isDisposed => _isDisposed;
|
||||
|
||||
/// Disposes the underlying ui.Image to free GPU memory.
|
||||
/// This is safe to call multiple times.
|
||||
/// Explicitly release the underlying GPU resource now.
|
||||
///
|
||||
/// Optional — if not called, the resource is freed when this wrapper is
|
||||
/// garbage collected. Only call this when you are certain no other holder
|
||||
/// still references the image; otherwise prefer to drop your reference
|
||||
/// and let GC handle it.
|
||||
void dispose() {
|
||||
if (_isDisposed) return;
|
||||
_isDisposed = true;
|
||||
// Delay disposal to allow widgets to finish rendering
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
_value?.dispose();
|
||||
_value = null;
|
||||
});
|
||||
_finalizer.detach(this);
|
||||
_value?.dispose();
|
||||
_value = null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user