2023-01-20 09:58:21 +03:00
|
|
|
import 'package:bottom_sheet_scaffold/bottom_sheet_scaffold.dart';
|
2022-12-25 12:30:20 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../controller/gallery_controller.dart';
|
|
|
|
import '../../../models/media_file.dart';
|
2022-12-29 12:12:06 +03:00
|
|
|
import '../thumbnail_media_file.dart';
|
2022-12-25 12:30:20 +03:00
|
|
|
|
|
|
|
class MediaView extends StatelessWidget {
|
|
|
|
final MediaFile file;
|
2022-12-30 05:18:18 +03:00
|
|
|
final PhoneGalleryController controller;
|
|
|
|
final bool singleMedia;
|
2023-01-20 09:58:21 +03:00
|
|
|
final bool isBottomSheet;
|
2022-12-30 05:18:18 +03:00
|
|
|
const MediaView(this.file,
|
2023-01-02 13:18:23 +03:00
|
|
|
{super.key,
|
|
|
|
required this.controller,
|
|
|
|
required this.singleMedia,
|
2023-01-20 09:58:21 +03:00
|
|
|
required this.isBottomSheet});
|
2022-12-25 12:30:20 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Stack(
|
|
|
|
fit: StackFit.expand,
|
|
|
|
children: [
|
2023-01-20 09:58:21 +03:00
|
|
|
ThumbnailMediaFile(
|
2023-01-21 07:48:26 +03:00
|
|
|
onLongPress: () async {
|
2023-01-20 09:58:21 +03:00
|
|
|
if (singleMedia) {
|
2023-01-21 07:24:37 +03:00
|
|
|
controller.selectedFiles.add(file);
|
2023-01-20 09:58:21 +03:00
|
|
|
if (controller.heroBuilder != null) {
|
2023-01-21 07:48:26 +03:00
|
|
|
await Navigator.of(context).push(
|
2023-01-20 09:58:21 +03:00
|
|
|
MaterialPageRoute<void>(builder: (BuildContext context) {
|
|
|
|
return controller.heroBuilder!(file.id, file, context);
|
|
|
|
}));
|
2023-01-21 08:02:53 +03:00
|
|
|
controller.update();
|
2023-01-21 07:04:12 +03:00
|
|
|
} else if (controller.multipleMediasBuilder != null) {
|
2023-01-21 07:48:26 +03:00
|
|
|
await Navigator.of(context).push(
|
2023-01-21 07:04:12 +03:00
|
|
|
MaterialPageRoute<void>(builder: (BuildContext context) {
|
|
|
|
return controller.multipleMediasBuilder!([file], context);
|
|
|
|
}));
|
2023-01-21 08:02:53 +03:00
|
|
|
controller.update();
|
2022-12-29 08:45:28 +03:00
|
|
|
} else {
|
2023-01-20 09:58:21 +03:00
|
|
|
controller.onSelect(controller.selectedFiles);
|
|
|
|
if (isBottomSheet) {
|
|
|
|
BottomSheetPanel.close();
|
2023-01-21 07:59:03 +03:00
|
|
|
controller.updatePickerListener();
|
2023-01-20 09:58:21 +03:00
|
|
|
} else {
|
|
|
|
Navigator.pop(context);
|
2023-01-21 07:59:03 +03:00
|
|
|
controller.updatePickerListener();
|
2023-01-20 09:58:21 +03:00
|
|
|
controller.disposeController();
|
|
|
|
}
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
2023-01-20 09:58:21 +03:00
|
|
|
} else {
|
|
|
|
controller.selectMedia(file);
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
2023-01-20 09:58:21 +03:00
|
|
|
},
|
2023-01-21 07:48:26 +03:00
|
|
|
onTap: () async {
|
2023-01-20 09:58:21 +03:00
|
|
|
if (controller.pickerMode) {
|
|
|
|
if (controller.isSelectedMedia(file)) {
|
|
|
|
controller.unselectMedia(file);
|
|
|
|
} else {
|
|
|
|
controller.selectMedia(file);
|
|
|
|
}
|
2022-12-25 12:30:20 +03:00
|
|
|
} else {
|
2023-01-21 07:24:37 +03:00
|
|
|
controller.selectedFiles.add(file);
|
2023-01-20 09:58:21 +03:00
|
|
|
if (controller.heroBuilder != null) {
|
2023-01-21 07:48:26 +03:00
|
|
|
await Navigator.of(context).push(
|
2023-01-20 09:58:21 +03:00
|
|
|
MaterialPageRoute<void>(builder: (BuildContext context) {
|
|
|
|
return controller.heroBuilder!(file.id, file, context);
|
|
|
|
}));
|
2023-01-21 08:02:53 +03:00
|
|
|
controller.update();
|
2023-01-21 07:04:12 +03:00
|
|
|
} else if (controller.multipleMediasBuilder != null) {
|
2023-01-21 07:48:26 +03:00
|
|
|
await Navigator.of(context).push(
|
2023-01-21 07:04:12 +03:00
|
|
|
MaterialPageRoute<void>(builder: (BuildContext context) {
|
|
|
|
return controller.multipleMediasBuilder!([file], context);
|
|
|
|
}));
|
2023-01-21 08:02:53 +03:00
|
|
|
controller.update();
|
2022-12-29 08:45:28 +03:00
|
|
|
} else {
|
2023-01-20 09:58:21 +03:00
|
|
|
controller.onSelect(controller.selectedFiles);
|
|
|
|
if (isBottomSheet) {
|
|
|
|
BottomSheetPanel.close();
|
2023-01-21 07:59:03 +03:00
|
|
|
controller.updatePickerListener();
|
2023-01-20 09:58:21 +03:00
|
|
|
} else {
|
|
|
|
Navigator.pop(context);
|
2023-01-21 07:59:03 +03:00
|
|
|
controller.updatePickerListener();
|
2023-01-20 09:58:21 +03:00
|
|
|
controller.disposeController();
|
|
|
|
}
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
2022-12-25 12:30:20 +03:00
|
|
|
}
|
|
|
|
},
|
2023-01-20 09:58:21 +03:00
|
|
|
file: file,
|
|
|
|
failIconColor: controller.config.appbarIconColor,
|
|
|
|
controller: controller),
|
2022-12-25 12:30:20 +03:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|