2023-06-27 23:00:20 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-11-20 16:58:03 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-02-08 06:07:50 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/views/video_viewer_page.dart';
|
2023-06-27 23:00:20 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
|
|
|
|
2024-01-31 01:47:47 +02:00
|
|
|
class MemoryCard extends StatelessWidget {
|
2023-06-27 23:00:20 +02:00
|
|
|
final Asset asset;
|
|
|
|
final String title;
|
|
|
|
final bool showTitle;
|
2024-02-08 06:07:50 +02:00
|
|
|
final Function()? onVideoEnded;
|
2023-06-27 23:00:20 +02:00
|
|
|
|
|
|
|
const MemoryCard({
|
|
|
|
required this.asset,
|
|
|
|
required this.title,
|
|
|
|
required this.showTitle,
|
2024-02-08 06:07:50 +02:00
|
|
|
this.onVideoEnded,
|
2023-06-27 23:00:20 +02:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
2024-02-04 22:35:13 +02:00
|
|
|
String get accessToken => Store.get(StoreKey.accessToken);
|
2023-06-27 23:00:20 +02:00
|
|
|
|
2024-01-31 01:47:47 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-27 23:00:20 +02:00
|
|
|
return Card(
|
|
|
|
color: Colors.black,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
|
|
side: const BorderSide(
|
|
|
|
color: Colors.black,
|
|
|
|
width: 1.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
2023-06-30 20:49:17 +02:00
|
|
|
ImageFiltered(
|
|
|
|
imageFilter: ImageFilter.blur(sigmaX: 30, sigmaY: 30),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image: CachedNetworkImageProvider(
|
|
|
|
getThumbnailUrl(
|
|
|
|
asset,
|
|
|
|
),
|
|
|
|
cacheKey: getThumbnailCacheKey(
|
|
|
|
asset,
|
|
|
|
),
|
2024-02-04 22:35:13 +02:00
|
|
|
headers: {"x-immich-user-token": accessToken},
|
2023-06-27 23:00:20 +02:00
|
|
|
),
|
2023-06-30 20:49:17 +02:00
|
|
|
fit: BoxFit.cover,
|
2023-06-27 23:00:20 +02:00
|
|
|
),
|
|
|
|
),
|
2023-06-30 20:49:17 +02:00
|
|
|
child: Container(color: Colors.black.withOpacity(0.2)),
|
2023-06-27 23:00:20 +02:00
|
|
|
),
|
|
|
|
),
|
2024-02-08 06:07:50 +02:00
|
|
|
LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
// Determine the fit using the aspect ratio
|
|
|
|
BoxFit fit = BoxFit.fitWidth;
|
|
|
|
if (asset.width != null && asset.height != null) {
|
|
|
|
final aspectRatio = asset.height! / asset.width!;
|
|
|
|
final phoneAspectRatio =
|
|
|
|
constraints.maxWidth / constraints.maxHeight;
|
|
|
|
// Look for a 25% difference in either direction
|
|
|
|
if (phoneAspectRatio * .75 < aspectRatio &&
|
|
|
|
phoneAspectRatio * 1.25 > aspectRatio) {
|
|
|
|
// Cover to look nice if we have nearly the same aspect ratio
|
|
|
|
fit = BoxFit.cover;
|
2024-02-05 21:12:33 +02:00
|
|
|
}
|
2024-02-08 06:07:50 +02:00
|
|
|
}
|
2024-02-05 21:12:33 +02:00
|
|
|
|
2024-02-08 06:07:50 +02:00
|
|
|
if (asset.isImage) {
|
2024-02-05 21:12:33 +02:00
|
|
|
return Hero(
|
|
|
|
tag: 'memory-${asset.id}',
|
|
|
|
child: ImmichImage(
|
|
|
|
asset,
|
|
|
|
fit: fit,
|
|
|
|
height: double.infinity,
|
|
|
|
width: double.infinity,
|
|
|
|
),
|
|
|
|
);
|
2024-02-08 06:07:50 +02:00
|
|
|
} else {
|
|
|
|
return Hero(
|
|
|
|
tag: 'memory-${asset.id}',
|
|
|
|
child: VideoViewerPage(
|
|
|
|
asset: asset,
|
|
|
|
showDownloadingIndicator: false,
|
|
|
|
placeholder: ImmichImage(
|
|
|
|
asset,
|
|
|
|
fit: fit,
|
|
|
|
),
|
|
|
|
hideControlsTimer: const Duration(seconds: 2),
|
|
|
|
onVideoEnded: onVideoEnded,
|
|
|
|
showControls: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-06-27 23:00:20 +02:00
|
|
|
),
|
|
|
|
if (showTitle)
|
|
|
|
Positioned(
|
|
|
|
left: 18.0,
|
|
|
|
bottom: 18.0,
|
2024-01-31 01:47:47 +02:00
|
|
|
child: Text(
|
|
|
|
title,
|
|
|
|
style: context.textTheme.headlineMedium?.copyWith(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-06-27 23:00:20 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|