2023-02-01 18:59:34 +02:00
|
|
|
import 'dart:io';
|
2023-06-26 18:54:08 +02:00
|
|
|
import 'dart:math';
|
2023-05-09 15:58:27 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-14 18:26:10 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-10-22 04:38:07 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/asset_stack.provider.dart';
|
2023-06-26 17:27:47 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/show_controls.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/video_player_controls_provider.dart';
|
2023-01-27 23:05:08 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/add_to_album_bottom_sheet.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/image_viewer_page_state.provider.dart';
|
2023-06-26 17:27:47 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/video_player_value_provider.dart';
|
2023-10-22 04:38:07 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/services/asset_stack.service.dart';
|
2023-04-11 19:21:00 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/advanced_bottom_sheet.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/exif_bottom_sheet.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/top_control_app_bar.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/views/video_viewer_page.dart';
|
2023-08-06 04:40:50 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/upload_dialog.dart';
|
2023-09-18 05:57:05 +02:00
|
|
|
import 'package:immich_mobile/shared/cache/original_image_provider.dart';
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-02-11 22:23:32 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
|
2022-08-16 01:53:30 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2023-03-15 23:29:07 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/photo_view_gallery.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/photo_view_computed_scale.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/photo_view_scale_state.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/utils/photo_view_hero_attributes.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-12-22 22:10:21 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
2023-10-23 20:28:12 +02:00
|
|
|
import 'package:isar/isar.dart';
|
2023-09-18 05:57:05 +02:00
|
|
|
import 'package:openapi/api.dart' show ThumbnailFormat;
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class GalleryViewerPage extends HookConsumerWidget {
|
2023-05-17 19:36:02 +02:00
|
|
|
final Asset Function(int index) loadAsset;
|
|
|
|
final int totalAssets;
|
|
|
|
final int initialIndex;
|
2023-07-13 17:42:06 +02:00
|
|
|
final int heroOffset;
|
2023-10-22 04:38:07 +02:00
|
|
|
final bool showStack;
|
2023-10-28 21:48:30 +02:00
|
|
|
final bool isOwner;
|
2023-11-06 17:46:26 +02:00
|
|
|
final String? sharedAlbumId;
|
2022-08-08 02:43:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
GalleryViewerPage({
|
2023-02-18 04:47:28 +02:00
|
|
|
super.key,
|
2023-05-17 19:36:02 +02:00
|
|
|
required this.initialIndex,
|
|
|
|
required this.loadAsset,
|
|
|
|
required this.totalAssets,
|
2023-07-13 17:42:06 +02:00
|
|
|
this.heroOffset = 0,
|
2023-10-22 04:38:07 +02:00
|
|
|
this.showStack = false,
|
2023-10-28 21:48:30 +02:00
|
|
|
this.isOwner = true,
|
2023-11-06 17:46:26 +02:00
|
|
|
this.sharedAlbumId,
|
2023-05-17 19:36:02 +02:00
|
|
|
}) : controller = PageController(initialPage: initialIndex);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2023-02-23 04:50:13 +02:00
|
|
|
final PageController controller;
|
2023-02-18 04:47:28 +02:00
|
|
|
|
2023-09-18 05:57:05 +02:00
|
|
|
static const jpeg = ThumbnailFormat.JPEG;
|
|
|
|
static const webp = ThumbnailFormat.WEBP;
|
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-12-02 22:55:10 +02:00
|
|
|
final settings = ref.watch(appSettingsServiceProvider);
|
|
|
|
final isLoadPreview = useState(AppSettingsEnum.loadPreview.defaultValue);
|
|
|
|
final isLoadOriginal = useState(AppSettingsEnum.loadOriginal.defaultValue);
|
2022-08-13 22:51:09 +02:00
|
|
|
final isZoomed = useState<bool>(false);
|
2022-11-19 07:12:54 +02:00
|
|
|
final isPlayingMotionVideo = useState(false);
|
2023-02-05 14:57:07 +02:00
|
|
|
final isPlayingVideo = useState(false);
|
2023-06-21 02:58:17 +02:00
|
|
|
Offset? localPosition;
|
2023-03-23 03:36:44 +02:00
|
|
|
final authToken = 'Bearer ${Store.get(StoreKey.accessToken)}';
|
2023-09-18 05:57:05 +02:00
|
|
|
final header = {"Authorization": authToken};
|
2023-05-17 19:36:02 +02:00
|
|
|
final currentIndex = useState(initialIndex);
|
|
|
|
final currentAsset = loadAsset(currentIndex.value);
|
2023-10-06 09:01:14 +02:00
|
|
|
final isTrashEnabled =
|
|
|
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
|
|
|
final navStack = AutoRouter.of(context).stackData;
|
|
|
|
final isFromTrash = isTrashEnabled &&
|
|
|
|
navStack.length > 2 &&
|
|
|
|
navStack.elementAt(navStack.length - 2).name == TrashRoute.name;
|
2023-10-22 04:38:07 +02:00
|
|
|
final stackIndex = useState(-1);
|
2023-10-26 16:19:06 +02:00
|
|
|
final stack = showStack && currentAsset.stackChildrenCount > 0
|
2023-10-22 04:38:07 +02:00
|
|
|
? ref.watch(assetStackStateProvider(currentAsset))
|
|
|
|
: <Asset>[];
|
|
|
|
final stackElements = showStack ? [currentAsset, ...stack] : <Asset>[];
|
2023-10-23 20:28:12 +02:00
|
|
|
// Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
|
2023-10-29 22:28:54 +02:00
|
|
|
final isFromDto = currentAsset.id == Isar.autoIncrement;
|
2023-05-17 19:36:02 +02:00
|
|
|
|
2023-10-22 04:38:07 +02:00
|
|
|
Asset asset() => stackIndex.value == -1
|
|
|
|
? currentAsset
|
|
|
|
: stackElements.elementAt(stackIndex.value);
|
|
|
|
|
|
|
|
bool isParent = stackIndex.value == -1 || stackIndex.value == 0;
|
2022-08-13 22:51:09 +02:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
2022-12-02 22:55:10 +02:00
|
|
|
isLoadPreview.value =
|
|
|
|
settings.getSetting<bool>(AppSettingsEnum.loadPreview);
|
|
|
|
isLoadOriginal.value =
|
|
|
|
settings.getSetting<bool>(AppSettingsEnum.loadOriginal);
|
2022-11-19 07:12:54 +02:00
|
|
|
isPlayingMotionVideo.value = false;
|
2022-08-13 22:51:09 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
void toggleFavorite(Asset asset) => ref
|
|
|
|
.watch(assetProvider.notifier)
|
|
|
|
.toggleFavorite([asset], !asset.isFavorite);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
/// Original (large) image of a remote asset. Required asset.isRemote
|
2023-09-18 05:57:05 +02:00
|
|
|
ImageProvider remoteOriginalProvider(Asset asset) =>
|
|
|
|
CachedNetworkImageProvider(
|
|
|
|
getImageUrl(asset),
|
|
|
|
cacheKey: getImageCacheKey(asset),
|
|
|
|
headers: header,
|
|
|
|
);
|
2023-02-01 18:59:34 +02:00
|
|
|
|
2023-09-18 05:57:05 +02:00
|
|
|
/// Original (large) image of a local asset. Required asset.isLocal
|
|
|
|
ImageProvider localOriginalProvider(Asset asset) =>
|
|
|
|
OriginalImageProvider(asset);
|
|
|
|
|
|
|
|
ImageProvider finalImageProvider(Asset asset) {
|
|
|
|
if (ImmichImage.useLocal(asset)) {
|
|
|
|
return localOriginalProvider(asset);
|
|
|
|
} else if (isLoadOriginal.value) {
|
|
|
|
return remoteOriginalProvider(asset);
|
|
|
|
} else if (isLoadPreview.value) {
|
|
|
|
return ImmichImage.remoteThumbnailProvider(asset, jpeg, header);
|
|
|
|
}
|
|
|
|
return ImmichImage.remoteThumbnailProvider(asset, webp, header);
|
2023-02-01 18:59:34 +02:00
|
|
|
}
|
|
|
|
|
2023-09-18 05:57:05 +02:00
|
|
|
Iterable<ImageProvider> allImageProviders(Asset asset) sync* {
|
|
|
|
if (ImmichImage.useLocal(asset)) {
|
|
|
|
yield ImmichImage.localThumbnailProvider(asset);
|
|
|
|
yield localOriginalProvider(asset);
|
|
|
|
} else {
|
|
|
|
yield ImmichImage.remoteThumbnailProvider(asset, webp, header);
|
|
|
|
if (isLoadPreview.value) {
|
|
|
|
yield ImmichImage.remoteThumbnailProvider(asset, jpeg, header);
|
|
|
|
}
|
|
|
|
if (isLoadOriginal.value) {
|
|
|
|
yield remoteOriginalProvider(asset);
|
|
|
|
}
|
|
|
|
}
|
2023-02-01 18:59:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void precacheNextImage(int index) {
|
2023-09-18 05:57:05 +02:00
|
|
|
void onError(Object exception, StackTrace? stackTrace) {
|
|
|
|
// swallow error silently
|
|
|
|
}
|
2023-05-17 19:36:02 +02:00
|
|
|
if (index < totalAssets && index >= 0) {
|
|
|
|
final asset = loadAsset(index);
|
2023-09-18 05:57:05 +02:00
|
|
|
for (final imageProvider in allImageProviders(asset)) {
|
|
|
|
precacheImage(imageProvider, context, onError: onError);
|
2023-02-01 18:59:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void showInfo() {
|
2023-02-04 22:42:42 +02:00
|
|
|
showModalBottomSheet(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
2023-04-11 19:21:00 +02:00
|
|
|
if (ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.getSetting<bool>(AppSettingsEnum.advancedTroubleshooting)) {
|
2023-05-17 19:36:02 +02:00
|
|
|
return AdvancedBottomSheet(assetDetail: asset());
|
2023-04-11 19:21:00 +02:00
|
|
|
}
|
2023-04-13 17:22:06 +02:00
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
|
|
),
|
2023-10-22 04:38:07 +02:00
|
|
|
child: ExifBottomSheet(asset: asset()),
|
2023-04-13 17:22:06 +02:00
|
|
|
);
|
2023-02-04 22:42:42 +02:00
|
|
|
},
|
|
|
|
);
|
2022-08-03 22:36:12 +02:00
|
|
|
}
|
|
|
|
|
2023-10-22 04:38:07 +02:00
|
|
|
void removeAssetFromStack() {
|
|
|
|
if (stackIndex.value > 0 && showStack) {
|
|
|
|
ref
|
|
|
|
.read(assetStackStateProvider(currentAsset).notifier)
|
|
|
|
.removeChild(stackIndex.value - 1);
|
|
|
|
stackIndex.value = stackIndex.value - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 09:01:14 +02:00
|
|
|
void handleDelete(Asset deleteAsset) async {
|
|
|
|
Future<bool> onDelete(bool force) async {
|
|
|
|
final isDeleted = await ref.read(assetProvider.notifier).deleteAssets(
|
|
|
|
{deleteAsset},
|
|
|
|
force: force,
|
|
|
|
);
|
2023-10-22 04:38:07 +02:00
|
|
|
if (isDeleted && isParent) {
|
2023-10-06 09:01:14 +02:00
|
|
|
if (totalAssets == 1) {
|
|
|
|
// Handle only one asset
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
} else {
|
|
|
|
// Go to next page otherwise
|
|
|
|
controller.nextPage(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
curve: Curves.fastLinearToSlowEaseIn,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isDeleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Asset is trashed
|
|
|
|
if (isTrashEnabled && !isFromTrash) {
|
|
|
|
final isDeleted = await onDelete(false);
|
2023-10-22 04:38:07 +02:00
|
|
|
if (isDeleted) {
|
|
|
|
// Can only trash assets stored in server. Local assets are always permanently removed for now
|
|
|
|
if (context.mounted && deleteAsset.isRemote && isParent) {
|
|
|
|
ImmichToast.show(
|
|
|
|
durationInSecond: 1,
|
|
|
|
context: context,
|
|
|
|
msg: 'Asset trashed',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
removeAssetFromStack();
|
2023-10-06 09:01:14 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Asset is permanently removed
|
2022-12-22 22:10:21 +02:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
2023-10-22 04:38:07 +02:00
|
|
|
return DeleteDialog(
|
|
|
|
onDelete: () async {
|
|
|
|
final isDeleted = await onDelete(true);
|
|
|
|
if (isDeleted) {
|
|
|
|
removeAssetFromStack();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2022-12-22 22:10:21 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-27 07:16:28 +02:00
|
|
|
void addToAlbum(Asset addToAlbumAsset) {
|
|
|
|
showModalBottomSheet(
|
2023-04-17 07:02:07 +02:00
|
|
|
elevation: 0,
|
2023-01-27 07:16:28 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
2023-01-27 23:05:08 +02:00
|
|
|
return AddToAlbumBottomSheet(
|
|
|
|
assets: [addToAlbumAsset],
|
2023-01-27 07:16:28 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-01 18:59:34 +02:00
|
|
|
void handleSwipeUpDown(DragUpdateDetails details) {
|
|
|
|
int sensitivity = 15;
|
2023-02-11 22:23:32 +02:00
|
|
|
int dxThreshold = 50;
|
2023-07-31 20:18:40 +02:00
|
|
|
double ratioThreshold = 3.0;
|
2023-02-01 18:59:34 +02:00
|
|
|
|
|
|
|
if (isZoomed.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-21 02:58:17 +02:00
|
|
|
// Guard [localPosition] null
|
|
|
|
if (localPosition == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-01 18:59:34 +02:00
|
|
|
// Check for delta from initial down point
|
2023-06-21 02:58:17 +02:00
|
|
|
final d = details.localPosition - localPosition!;
|
2023-02-01 18:59:34 +02:00
|
|
|
// If the magnitude of the dx swipe is large, we probably didn't mean to go down
|
2023-02-11 22:23:32 +02:00
|
|
|
if (d.dx.abs() > dxThreshold) {
|
2023-02-01 18:59:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-31 20:18:40 +02:00
|
|
|
final ratio = d.dy / max(d.dx.abs(), 1);
|
|
|
|
if (d.dy > sensitivity && ratio > ratioThreshold) {
|
2023-02-01 18:59:34 +02:00
|
|
|
AutoRouter.of(context).pop();
|
2023-07-31 20:18:40 +02:00
|
|
|
} else if (d.dy < -sensitivity && ratio < -ratioThreshold) {
|
2023-02-01 18:59:34 +02:00
|
|
|
showInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 07:02:07 +02:00
|
|
|
shareAsset() {
|
2023-05-17 19:36:02 +02:00
|
|
|
ref.watch(imageViewerStateProvider.notifier).shareAsset(asset(), context);
|
2023-04-17 07:02:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleArchive(Asset asset) {
|
|
|
|
ref
|
|
|
|
.watch(assetProvider.notifier)
|
|
|
|
.toggleArchive([asset], !asset.isArchived);
|
2023-10-22 04:38:07 +02:00
|
|
|
if (isParent) {
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeAssetFromStack();
|
2023-04-17 07:02:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-06 04:40:50 +02:00
|
|
|
handleUpload(Asset asset) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
|
|
|
return UploadDialog(
|
|
|
|
onUpload: () {
|
|
|
|
ref
|
|
|
|
.read(manualUploadProvider.notifier)
|
|
|
|
.uploadAssets(context, [asset]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-06 17:46:26 +02:00
|
|
|
handleActivities() {
|
|
|
|
if (sharedAlbumId != null) {
|
|
|
|
AutoRouter.of(context).push(
|
|
|
|
ActivitiesRoute(
|
|
|
|
albumId: sharedAlbumId!,
|
|
|
|
assetId: asset().remoteId,
|
|
|
|
withAssetThumbs: false,
|
|
|
|
isOwner: isOwner,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:26:05 +02:00
|
|
|
buildAppBar() {
|
2023-06-11 20:10:17 +02:00
|
|
|
return IgnorePointer(
|
2023-06-26 17:27:47 +02:00
|
|
|
ignoring: !ref.watch(showControlsProvider),
|
2023-06-11 20:10:17 +02:00
|
|
|
child: AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
2023-06-26 17:27:47 +02:00
|
|
|
opacity: ref.watch(showControlsProvider) ? 1.0 : 0.0,
|
2023-06-11 20:10:17 +02:00
|
|
|
child: Container(
|
|
|
|
color: Colors.black.withOpacity(0.4),
|
|
|
|
child: TopControlAppBar(
|
2023-10-28 21:48:30 +02:00
|
|
|
isOwner: isOwner,
|
2023-06-11 20:10:17 +02:00
|
|
|
isPlayingMotionVideo: isPlayingMotionVideo.value,
|
|
|
|
asset: asset(),
|
|
|
|
onMoreInfoPressed: showInfo,
|
2023-10-12 04:10:59 +02:00
|
|
|
onFavorite: toggleFavorite,
|
2023-08-06 04:40:50 +02:00
|
|
|
onUploadPressed:
|
|
|
|
asset().isLocal ? () => handleUpload(asset()) : null,
|
2023-06-11 20:10:17 +02:00
|
|
|
onDownloadPressed: asset().isLocal
|
|
|
|
? null
|
|
|
|
: () => ref
|
|
|
|
.watch(imageViewerStateProvider.notifier)
|
|
|
|
.downloadAsset(
|
|
|
|
asset(),
|
|
|
|
context,
|
|
|
|
),
|
|
|
|
onToggleMotionVideo: (() {
|
|
|
|
isPlayingMotionVideo.value = !isPlayingMotionVideo.value;
|
|
|
|
}),
|
|
|
|
onAddToAlbumPressed: () => addToAlbum(asset()),
|
2023-11-06 17:46:26 +02:00
|
|
|
shareAlbumId: sharedAlbumId,
|
|
|
|
onActivitiesPressed: handleActivities,
|
2023-06-11 20:10:17 +02:00
|
|
|
),
|
2023-02-03 18:26:05 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:27:47 +02:00
|
|
|
Widget buildProgressBar() {
|
|
|
|
final playerValue = ref.watch(videoPlaybackValueProvider);
|
|
|
|
|
|
|
|
return Expanded(
|
|
|
|
child: Slider(
|
|
|
|
value: playerValue.duration == Duration.zero
|
|
|
|
? 0.0
|
2023-06-26 18:54:08 +02:00
|
|
|
: min(
|
|
|
|
playerValue.position.inMicroseconds /
|
|
|
|
playerValue.duration.inMicroseconds *
|
|
|
|
100,
|
2023-06-26 17:27:47 +02:00
|
|
|
100,
|
2023-06-26 18:54:08 +02:00
|
|
|
),
|
2023-06-26 17:27:47 +02:00
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
thumbColor: Colors.white,
|
|
|
|
activeColor: Colors.white,
|
|
|
|
inactiveColor: Colors.white.withOpacity(0.75),
|
|
|
|
onChanged: (position) {
|
|
|
|
ref.read(videoPlayerControlsProvider.notifier).position = position;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Text buildPosition() {
|
|
|
|
final position = ref
|
|
|
|
.watch(videoPlaybackValueProvider.select((value) => value.position));
|
|
|
|
|
|
|
|
return Text(
|
|
|
|
_formatDuration(position),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.0,
|
|
|
|
color: Colors.white.withOpacity(.75),
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Text buildDuration() {
|
|
|
|
final duration = ref
|
|
|
|
.watch(videoPlaybackValueProvider.select((value) => value.duration));
|
|
|
|
|
|
|
|
return Text(
|
|
|
|
_formatDuration(duration),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.0,
|
|
|
|
color: Colors.white.withOpacity(.75),
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-06-11 20:10:17 +02:00
|
|
|
|
2023-06-26 17:27:47 +02:00
|
|
|
Widget buildMuteButton() {
|
|
|
|
return IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
ref.watch(videoPlayerControlsProvider.select((value) => value.mute))
|
|
|
|
? Icons.volume_off
|
|
|
|
: Icons.volume_up,
|
|
|
|
),
|
|
|
|
onPressed: () =>
|
|
|
|
ref.read(videoPlayerControlsProvider.notifier).toggleMute(),
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-22 04:38:07 +02:00
|
|
|
Widget buildStackedChildren() {
|
|
|
|
return ListView.builder(
|
|
|
|
shrinkWrap: true,
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: stackElements.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final assetId = stackElements.elementAt(index).remoteId;
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 10),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => stackIndex.value = index,
|
|
|
|
child: Container(
|
|
|
|
width: 40,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
2023-11-04 03:43:43 +02:00
|
|
|
border: (stackIndex.value == -1 && index == 0) ||
|
|
|
|
index == stackIndex.value
|
2023-10-22 04:38:07 +02:00
|
|
|
? Border.all(
|
|
|
|
color: Colors.white,
|
|
|
|
width: 2,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(4),
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
imageUrl:
|
|
|
|
'${Store.get(StoreKey.serverEndpoint)}/asset/thumbnail/$assetId',
|
|
|
|
httpHeaders: {
|
|
|
|
"Authorization":
|
|
|
|
"Bearer ${Store.get(StoreKey.accessToken)}",
|
|
|
|
},
|
|
|
|
errorWidget: (context, url, error) =>
|
|
|
|
const Icon(Icons.image_not_supported_outlined),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showStackActionItems() {
|
|
|
|
showModalBottomSheet<void>(
|
|
|
|
context: context,
|
|
|
|
enableDrag: false,
|
|
|
|
builder: (BuildContext ctx) {
|
|
|
|
return SafeArea(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
if (!isParent)
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.bookmark_border_outlined,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
await ref
|
|
|
|
.read(assetStackServiceProvider)
|
|
|
|
.updateStackParent(
|
|
|
|
currentAsset,
|
|
|
|
stackElements.elementAt(stackIndex.value),
|
|
|
|
);
|
|
|
|
Navigator.pop(ctx);
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"viewer_stack_use_as_main_asset",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.copy_all_outlined,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
if (isParent) {
|
|
|
|
await ref
|
|
|
|
.read(assetStackServiceProvider)
|
|
|
|
.updateStackParent(
|
|
|
|
currentAsset,
|
|
|
|
stackElements
|
|
|
|
.elementAt(1), // Next asset as parent
|
|
|
|
);
|
|
|
|
// Remove itself from stack
|
|
|
|
await ref.read(assetStackServiceProvider).updateStack(
|
|
|
|
stackElements.elementAt(1),
|
|
|
|
childrenToRemove: [currentAsset],
|
|
|
|
);
|
|
|
|
Navigator.pop(ctx);
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
} else {
|
|
|
|
await ref.read(assetStackServiceProvider).updateStack(
|
|
|
|
currentAsset,
|
|
|
|
childrenToRemove: [
|
|
|
|
stackElements.elementAt(stackIndex.value),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
removeAssetFromStack();
|
|
|
|
Navigator.pop(ctx);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"viewer_remove_from_stack",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.filter_none_outlined,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
await ref.read(assetStackServiceProvider).updateStack(
|
|
|
|
currentAsset,
|
|
|
|
childrenToRemove: stack,
|
|
|
|
);
|
|
|
|
Navigator.pop(ctx);
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"viewer_unstack",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildBottomBar() {
|
|
|
|
// !!!! itemsList and actionlist should always be in sync
|
|
|
|
final itemsList = [
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(
|
|
|
|
Platform.isAndroid ? Icons.share_rounded : Icons.ios_share_rounded,
|
|
|
|
),
|
|
|
|
label: 'control_bottom_app_bar_share'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_share'.tr(),
|
|
|
|
),
|
2023-10-28 21:48:30 +02:00
|
|
|
if (isOwner)
|
|
|
|
asset().isArchived
|
|
|
|
? BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.unarchive_rounded),
|
|
|
|
label: 'control_bottom_app_bar_unarchive'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_unarchive'.tr(),
|
|
|
|
)
|
|
|
|
: BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.archive_outlined),
|
|
|
|
label: 'control_bottom_app_bar_archive'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_archive'.tr(),
|
|
|
|
),
|
|
|
|
if (isOwner && stack.isNotEmpty)
|
2023-10-22 04:38:07 +02:00
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.burst_mode_outlined),
|
|
|
|
label: 'control_bottom_app_bar_stack'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_stack'.tr(),
|
|
|
|
),
|
2023-10-28 21:48:30 +02:00
|
|
|
if (isOwner)
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.delete_outline),
|
|
|
|
label: 'control_bottom_app_bar_delete'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_delete'.tr(),
|
|
|
|
),
|
|
|
|
if (!isOwner)
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.download_outlined),
|
|
|
|
label: 'download'.tr(),
|
|
|
|
tooltip: 'download'.tr(),
|
|
|
|
),
|
2023-10-22 04:38:07 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
List<Function(int)> actionslist = [
|
|
|
|
(_) => shareAsset(),
|
2023-10-28 21:48:30 +02:00
|
|
|
if (isOwner) (_) => handleArchive(asset()),
|
|
|
|
if (isOwner && stack.isNotEmpty) (_) => showStackActionItems(),
|
|
|
|
if (isOwner) (_) => handleDelete(asset()),
|
|
|
|
if (!isOwner)
|
|
|
|
(_) => asset().isLocal
|
|
|
|
? null
|
|
|
|
: ref.watch(imageViewerStateProvider.notifier).downloadAsset(
|
|
|
|
asset(),
|
|
|
|
context,
|
|
|
|
),
|
2023-10-22 04:38:07 +02:00
|
|
|
];
|
|
|
|
|
2023-06-11 20:10:17 +02:00
|
|
|
return IgnorePointer(
|
2023-06-26 17:27:47 +02:00
|
|
|
ignoring: !ref.watch(showControlsProvider),
|
2023-06-11 20:10:17 +02:00
|
|
|
child: AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
2023-06-26 17:27:47 +02:00
|
|
|
opacity: ref.watch(showControlsProvider) ? 1.0 : 0.0,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2023-10-22 04:38:07 +02:00
|
|
|
if (stack.isNotEmpty)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 10,
|
|
|
|
bottom: 30,
|
|
|
|
),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 40,
|
|
|
|
child: buildStackedChildren(),
|
|
|
|
),
|
|
|
|
),
|
2023-06-26 17:27:47 +02:00
|
|
|
Visibility(
|
|
|
|
visible: !asset().isImage && !isPlayingMotionVideo.value,
|
|
|
|
child: Container(
|
|
|
|
color: Colors.black.withOpacity(0.4),
|
|
|
|
child: Padding(
|
|
|
|
padding: MediaQuery.of(context).orientation ==
|
|
|
|
Orientation.portrait
|
|
|
|
? const EdgeInsets.symmetric(horizontal: 12.0)
|
|
|
|
: const EdgeInsets.symmetric(horizontal: 64.0),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
buildPosition(),
|
|
|
|
buildProgressBar(),
|
|
|
|
buildDuration(),
|
|
|
|
buildMuteButton(),
|
|
|
|
],
|
2023-06-11 20:10:17 +02:00
|
|
|
),
|
2023-06-26 17:27:47 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
BottomNavigationBar(
|
|
|
|
backgroundColor: Colors.black.withOpacity(0.4),
|
|
|
|
unselectedIconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
selectedIconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
unselectedLabelStyle: const TextStyle(color: Colors.black),
|
|
|
|
selectedLabelStyle: const TextStyle(color: Colors.black),
|
|
|
|
showSelectedLabels: false,
|
|
|
|
showUnselectedLabels: false,
|
2023-10-22 04:38:07 +02:00
|
|
|
items: itemsList,
|
2023-06-26 17:27:47 +02:00
|
|
|
onTap: (index) {
|
2023-10-22 04:38:07 +02:00
|
|
|
if (index < actionslist.length) {
|
|
|
|
actionslist[index].call(index);
|
2023-06-26 17:27:47 +02:00
|
|
|
}
|
|
|
|
},
|
2023-06-11 20:10:17 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-04-17 07:02:07 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:27:47 +02:00
|
|
|
ref.listen(showControlsProvider, (_, show) {
|
|
|
|
if (show) {
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
|
|
} else {
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
2023-03-06 06:51:18 +02:00
|
|
|
body: WillPopScope(
|
|
|
|
onWillPop: () async {
|
|
|
|
// Change immersive mode back to normal "edgeToEdge" mode
|
|
|
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
PhotoViewGallery.builder(
|
|
|
|
scaleStateChangedCallback: (state) {
|
|
|
|
isZoomed.value = state != PhotoViewScaleState.initial;
|
2023-07-22 21:56:49 +02:00
|
|
|
ref.read(showControlsProvider.notifier).show = !isZoomed.value;
|
2023-03-06 06:51:18 +02:00
|
|
|
},
|
|
|
|
pageController: controller,
|
|
|
|
scrollPhysics: isZoomed.value
|
|
|
|
? const NeverScrollableScrollPhysics() // Don't allow paging while scrolled in
|
|
|
|
: (Platform.isIOS
|
2023-04-18 18:23:56 +02:00
|
|
|
? const ScrollPhysics() // Use bouncing physics for iOS
|
2023-03-06 06:51:18 +02:00
|
|
|
: const ClampingScrollPhysics() // Use heavy physics for Android
|
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
itemCount: totalAssets,
|
2023-03-06 06:51:18 +02:00
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
onPageChanged: (value) {
|
2023-09-18 05:57:05 +02:00
|
|
|
final next = currentIndex.value < value ? value + 1 : value - 1;
|
|
|
|
precacheNextImage(next);
|
2023-05-17 19:36:02 +02:00
|
|
|
currentIndex.value = value;
|
2023-10-22 04:38:07 +02:00
|
|
|
stackIndex.value = -1;
|
2023-03-06 06:51:18 +02:00
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
},
|
2023-09-18 05:57:05 +02:00
|
|
|
loadingBuilder: (context, event, index) {
|
|
|
|
final a = loadAsset(index);
|
|
|
|
if (ImmichImage.useLocal(a)) {
|
|
|
|
return Image(
|
|
|
|
image: ImmichImage.localThumbnailProvider(a),
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Use the WEBP Thumbnail as a placeholder for the JPEG thumbnail to achieve
|
|
|
|
// Three-Stage Loading (WEBP -> JPEG -> Original)
|
|
|
|
final webPThumbnail = CachedNetworkImage(
|
|
|
|
imageUrl: getThumbnailUrl(a, type: webp),
|
|
|
|
cacheKey: getThumbnailCacheKey(a, type: webp),
|
|
|
|
httpHeaders: header,
|
|
|
|
progressIndicatorBuilder: (_, __, ___) => const Center(
|
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
),
|
|
|
|
fadeInDuration: const Duration(milliseconds: 0),
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
errorWidget: (context, url, error) =>
|
|
|
|
const Icon(Icons.image_not_supported_outlined),
|
|
|
|
);
|
|
|
|
|
|
|
|
// loading the preview in the loadingBuilder only
|
|
|
|
// makes sense if the original is loaded in the builder
|
|
|
|
return isLoadPreview.value && isLoadOriginal.value
|
|
|
|
? CachedNetworkImage(
|
|
|
|
imageUrl: getThumbnailUrl(a, type: jpeg),
|
|
|
|
cacheKey: getThumbnailCacheKey(a, type: jpeg),
|
|
|
|
httpHeaders: header,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 0),
|
|
|
|
placeholder: (_, __) => webPThumbnail,
|
|
|
|
errorWidget: (_, __, ___) => webPThumbnail,
|
|
|
|
)
|
|
|
|
: webPThumbnail;
|
|
|
|
},
|
2023-03-06 06:51:18 +02:00
|
|
|
builder: (context, index) {
|
2023-10-22 04:38:07 +02:00
|
|
|
final a =
|
|
|
|
index == currentIndex.value ? asset() : loadAsset(index);
|
|
|
|
final ImageProvider provider = finalImageProvider(a);
|
2023-06-20 23:17:43 +02:00
|
|
|
|
2023-10-22 04:38:07 +02:00
|
|
|
if (a.isImage && !isPlayingMotionVideo.value) {
|
2023-03-06 06:51:18 +02:00
|
|
|
return PhotoViewGalleryPageOptions(
|
|
|
|
onDragStart: (_, details, __) =>
|
|
|
|
localPosition = details.localPosition,
|
2023-03-15 23:29:07 +02:00
|
|
|
onDragUpdate: (_, details, __) =>
|
|
|
|
handleSwipeUpDown(details),
|
2023-06-26 17:27:47 +02:00
|
|
|
onTapDown: (_, __, ___) {
|
|
|
|
ref.read(showControlsProvider.notifier).toggle();
|
|
|
|
},
|
2023-03-06 06:51:18 +02:00
|
|
|
imageProvider: provider,
|
|
|
|
heroAttributes: PhotoViewHeroAttributes(
|
2023-10-29 22:28:54 +02:00
|
|
|
tag: isFromDto
|
2023-10-23 20:28:12 +02:00
|
|
|
? '${a.remoteId}-$heroOffset'
|
|
|
|
: a.id + heroOffset,
|
2023-03-06 06:51:18 +02:00
|
|
|
),
|
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
tightMode: true,
|
|
|
|
minScale: PhotoViewComputedScale.contained,
|
2023-03-15 23:29:07 +02:00
|
|
|
errorBuilder: (context, error, stackTrace) => ImmichImage(
|
2023-10-22 04:38:07 +02:00
|
|
|
a,
|
2023-03-15 23:29:07 +02:00
|
|
|
fit: BoxFit.contain,
|
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
);
|
2023-02-01 18:59:34 +02:00
|
|
|
} else {
|
2023-03-06 06:51:18 +02:00
|
|
|
return PhotoViewGalleryPageOptions.customChild(
|
|
|
|
onDragStart: (_, details, __) =>
|
|
|
|
localPosition = details.localPosition,
|
2023-03-15 23:29:07 +02:00
|
|
|
onDragUpdate: (_, details, __) =>
|
|
|
|
handleSwipeUpDown(details),
|
2023-03-06 06:51:18 +02:00
|
|
|
heroAttributes: PhotoViewHeroAttributes(
|
2023-10-29 22:28:54 +02:00
|
|
|
tag: isFromDto
|
2023-10-23 20:28:12 +02:00
|
|
|
? '${a.remoteId}-$heroOffset'
|
|
|
|
: a.id + heroOffset,
|
2023-02-04 22:42:42 +02:00
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
maxScale: 1.0,
|
|
|
|
minScale: 1.0,
|
2023-06-26 17:27:47 +02:00
|
|
|
basePosition: Alignment.center,
|
2023-06-20 23:17:43 +02:00
|
|
|
child: VideoViewerPage(
|
|
|
|
onPlaying: () => isPlayingVideo.value = true,
|
2023-10-23 20:28:12 +02:00
|
|
|
onPaused: () =>
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback(
|
|
|
|
(_) => isPlayingVideo.value = false,
|
|
|
|
),
|
2023-10-22 04:38:07 +02:00
|
|
|
asset: a,
|
2023-06-20 23:17:43 +02:00
|
|
|
isMotionVideo: isPlayingMotionVideo.value,
|
|
|
|
placeholder: Image(
|
|
|
|
image: provider,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
height: MediaQuery.of(context).size.height,
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
alignment: Alignment.center,
|
2023-03-06 06:51:18 +02:00
|
|
|
),
|
2023-06-20 23:17:43 +02:00
|
|
|
onVideoEnded: () {
|
|
|
|
if (isPlayingMotionVideo.value) {
|
|
|
|
isPlayingMotionVideo.value = false;
|
|
|
|
}
|
|
|
|
},
|
2023-03-06 06:51:18 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: buildAppBar(),
|
|
|
|
),
|
2023-04-17 07:02:07 +02:00
|
|
|
Positioned(
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: buildBottomBar(),
|
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-03 22:36:12 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-06-26 17:27:47 +02:00
|
|
|
|
|
|
|
String _formatDuration(Duration position) {
|
|
|
|
final ms = position.inMilliseconds;
|
|
|
|
|
|
|
|
int seconds = ms ~/ 1000;
|
|
|
|
final int hours = seconds ~/ 3600;
|
|
|
|
seconds = seconds % 3600;
|
|
|
|
final minutes = seconds ~/ 60;
|
|
|
|
seconds = seconds % 60;
|
|
|
|
|
|
|
|
final hoursString = hours >= 10
|
|
|
|
? '$hours'
|
|
|
|
: hours == 0
|
|
|
|
? '00'
|
|
|
|
: '0$hours';
|
|
|
|
|
|
|
|
final minutesString = minutes >= 10
|
|
|
|
? '$minutes'
|
|
|
|
: minutes == 0
|
|
|
|
? '00'
|
|
|
|
: '0$minutes';
|
|
|
|
|
|
|
|
final secondsString = seconds >= 10
|
|
|
|
? '$seconds'
|
|
|
|
: seconds == 0
|
|
|
|
? '00'
|
|
|
|
: '0$seconds';
|
|
|
|
|
|
|
|
final formattedTime =
|
|
|
|
'${hoursString == '00' ? '' : '$hoursString:'}$minutesString:$secondsString';
|
|
|
|
|
|
|
|
return formattedTime;
|
|
|
|
}
|
2022-08-03 22:36:12 +02:00
|
|
|
}
|