mirror of
https://github.com/ente-io/ente.git
synced 2025-08-07 23:18:10 +00:00
[mob][photos] Store face crop as state
This commit is contained in:
parent
0cfcb83438
commit
d1e82b9261
@ -14,7 +14,7 @@ import "package:photos/ui/common/loading_widget.dart";
|
|||||||
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
|
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
|
||||||
import "package:photos/utils/face/face_box_crop.dart";
|
import "package:photos/utils/face/face_box_crop.dart";
|
||||||
|
|
||||||
class PersonFaceWidget extends StatelessWidget {
|
class PersonFaceWidget extends StatefulWidget {
|
||||||
final EnteFile file;
|
final EnteFile file;
|
||||||
final String? personId;
|
final String? personId;
|
||||||
final String? clusterID;
|
final String? clusterID;
|
||||||
@ -39,21 +39,25 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
"PersonFaceWidget requires either personId or clusterID to be non-null",
|
"PersonFaceWidget requires either personId or clusterID to be non-null",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PersonFaceWidget> createState() => _PersonFaceWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PersonFaceWidgetState extends State<PersonFaceWidget> {
|
||||||
|
Future<Uint8List?>? faceCropFuture;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
faceCropFuture = widget.faceCrop != null
|
||||||
|
? Future.value(widget.faceCrop)
|
||||||
|
: _getFaceCrop();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (faceCrop != null) {
|
|
||||||
return Stack(
|
|
||||||
fit: StackFit.expand,
|
|
||||||
children: [
|
|
||||||
Image(
|
|
||||||
image: MemoryImage(faceCrop!),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return FutureBuilder<Uint8List?>(
|
return FutureBuilder<Uint8List?>(
|
||||||
future: _getFaceCrop(),
|
future: faceCropFuture,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
final ImageProvider imageProvider = MemoryImage(snapshot.data!);
|
final ImageProvider imageProvider = MemoryImage(snapshot.data!);
|
||||||
@ -70,8 +74,8 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
log('Error getting cover face for person: ${snapshot.error}');
|
log('Error getting cover face for person: ${snapshot.error}');
|
||||||
}
|
}
|
||||||
return thumbnailFallback
|
return widget.thumbnailFallback
|
||||||
? ThumbnailWidget(file)
|
? ThumbnailWidget(widget.file)
|
||||||
: EnteLoadingWidget(
|
: EnteLoadingWidget(
|
||||||
color: getEnteColorScheme(context).fillMuted,
|
color: getEnteColorScheme(context).fillMuted,
|
||||||
);
|
);
|
||||||
@ -82,11 +86,11 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
|
|
||||||
Future<Uint8List?> _getFaceCrop() async {
|
Future<Uint8List?> _getFaceCrop() async {
|
||||||
try {
|
try {
|
||||||
EnteFile? fileForFaceCrop = file;
|
EnteFile? fileForFaceCrop = widget.file;
|
||||||
String? personAvatarFaceID;
|
String? personAvatarFaceID;
|
||||||
if (personId != null) {
|
if (widget.personId != null) {
|
||||||
final PersonEntity? personEntity =
|
final PersonEntity? personEntity =
|
||||||
await PersonService.instance.getPerson(personId!);
|
await PersonService.instance.getPerson(widget.personId!);
|
||||||
if (personEntity != null) {
|
if (personEntity != null) {
|
||||||
personAvatarFaceID = personEntity.data.avatarFaceID;
|
personAvatarFaceID = personEntity.data.avatarFaceID;
|
||||||
if (personAvatarFaceID != null) {
|
if (personAvatarFaceID != null) {
|
||||||
@ -94,9 +98,9 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
await checkGetCachedCropForFaceID(personAvatarFaceID);
|
await checkGetCachedCropForFaceID(personAvatarFaceID);
|
||||||
if (tryCache != null) return tryCache;
|
if (tryCache != null) return tryCache;
|
||||||
}
|
}
|
||||||
if (personAvatarFaceID == null && cannotTrustFile) {
|
if (personAvatarFaceID == null && widget.cannotTrustFile) {
|
||||||
final allFaces =
|
final allFaces =
|
||||||
await MLDataDB.instance.getFaceIDsForPerson(personId!);
|
await MLDataDB.instance.getFaceIDsForPerson(widget.personId!);
|
||||||
final allFileIDs = allFaces.map((e) => getFileIdFromFaceId(e));
|
final allFileIDs = allFaces.map((e) => getFileIdFromFaceId(e));
|
||||||
final fileIDToCreationTime =
|
final fileIDToCreationTime =
|
||||||
await FilesDB.instance.getFileIDToCreationTime();
|
await FilesDB.instance.getFileIDToCreationTime();
|
||||||
@ -124,12 +128,12 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
|
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
|
||||||
recentFileID: fileForFaceCrop.uploadedFileID!,
|
recentFileID: fileForFaceCrop.uploadedFileID!,
|
||||||
avatarFaceId: personAvatarFaceID,
|
avatarFaceId: personAvatarFaceID,
|
||||||
personID: personId,
|
personID: widget.personId,
|
||||||
clusterID: clusterID,
|
clusterID: widget.clusterID,
|
||||||
);
|
);
|
||||||
if (face == null) {
|
if (face == null) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"No cover face for person: $personId and cluster $clusterID and recentFile ${file.uploadedFileID}",
|
"No cover face for person: ${widget.personId} and cluster ${widget.clusterID} and recentFile ${widget.file.uploadedFileID}",
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -141,12 +145,12 @@ class PersonFaceWidget extends StatelessWidget {
|
|||||||
final cropMap = await getCachedFaceCrops(
|
final cropMap = await getCachedFaceCrops(
|
||||||
fileForFaceCrop,
|
fileForFaceCrop,
|
||||||
[face],
|
[face],
|
||||||
useFullFile: useFullFile,
|
useFullFile: widget.useFullFile,
|
||||||
);
|
);
|
||||||
return cropMap?[face.faceID];
|
return cropMap?[face.faceID];
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
log(
|
log(
|
||||||
"Error getting cover face for person: $personId and cluster $clusterID",
|
"Error getting cover face for person: ${widget.personId} and cluster ${widget.clusterID}",
|
||||||
error: e,
|
error: e,
|
||||||
stackTrace: s,
|
stackTrace: s,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user