mirror of
https://github.com/immich-app/immich.git
synced 2025-01-19 18:26:46 +01:00
Uses blurhash ref instead of state
This commit is contained in:
parent
c2694996e5
commit
1eb96fa9e9
2 changed files with 6 additions and 10 deletions
|
@ -1,18 +1,17 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:immich_mobile/shared/models/asset.dart';
|
import 'package:immich_mobile/shared/models/asset.dart';
|
||||||
import 'package:thumbhash/thumbhash.dart' as thumbhash;
|
import 'package:thumbhash/thumbhash.dart' as thumbhash;
|
||||||
|
|
||||||
ValueNotifier<Uint8List?> useBlurHashState(Asset? asset) {
|
ObjectRef<Uint8List?> useBlurHashRef(Asset? asset) {
|
||||||
if (asset?.thumbhash == null) {
|
if (asset?.thumbhash == null) {
|
||||||
return useState(null);
|
return useRef(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
final rbga = thumbhash.thumbHashToRGBA(
|
final rbga = thumbhash.thumbHashToRGBA(
|
||||||
base64Decode(asset!.thumbhash!),
|
base64Decode(asset!.thumbhash!),
|
||||||
);
|
);
|
||||||
|
|
||||||
return useState(thumbhash.rgbaToBmp(rbga));
|
return useRef(thumbhash.rgbaToBmp(rbga));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,10 @@ class ImmichThumbnail extends HookWidget {
|
||||||
final double height;
|
final double height;
|
||||||
final BoxFit fit;
|
final BoxFit fit;
|
||||||
|
|
||||||
// Helper function to return the image provider for the asset
|
/// Helper function to return the image provider for the asset thumbnail
|
||||||
// either by using the asset ID or the asset itself
|
/// either by using the asset ID or the asset itself
|
||||||
/// [asset] is the Asset to request, or else use [assetId] to get a remote
|
/// [asset] is the Asset to request, or else use [assetId] to get a remote
|
||||||
/// image provider
|
/// image provider
|
||||||
/// Use [isThumbnail] and [thumbnailSize] if you'd like to request a thumbnail
|
|
||||||
/// The size of the square thumbnail to request. Ignored if isThumbnail
|
|
||||||
/// is not true
|
|
||||||
static ImageProvider imageProvider({
|
static ImageProvider imageProvider({
|
||||||
Asset? asset,
|
Asset? asset,
|
||||||
String? assetId,
|
String? assetId,
|
||||||
|
@ -64,7 +61,7 @@ class ImmichThumbnail extends HookWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Uint8List? blurhash = useBlurHashState(asset).value;
|
Uint8List? blurhash = useBlurHashRef(asset).value;
|
||||||
if (asset == null) {
|
if (asset == null) {
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
|
|
Loading…
Reference in a new issue