ente/lib/ui/viewer/search/location_collection_page.dart
2022-08-04 21:46:16 +05:30

88 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/files_updated_event.dart';
import 'package:photos/models/file_load_result.dart';
import 'package:photos/models/gallery_type.dart';
import 'package:photos/models/search/location_search_result.dart';
import 'package:photos/models/selected_files.dart';
import 'package:photos/ui/viewer/gallery/gallery.dart';
import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
import 'package:photos/ui/viewer/gallery/gallery_overlay_widget.dart';
class LocationCollectionPage extends StatelessWidget {
final LocationSearchResult locationAndFiles;
final String tagPrefix;
final GalleryType appBarType;
final GalleryType overlayType;
final _selectedFiles = SelectedFiles();
LocationCollectionPage({
this.locationAndFiles,
this.tagPrefix = "location_collection_page",
this.appBarType = GalleryType.archive,
this.overlayType = GalleryType.archive,
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final gallery = Gallery(
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
final result = locationAndFiles.files
.where(
(file) =>
file.creationTime >= creationStartTime &&
file.creationTime <= creationEndTime,
)
.toList();
return Future.value(
FileLoadResult(result, result.length < locationAndFiles.files.length),
);
},
reloadEvent: Bus.instance.on<FilesUpdatedEvent>().where(
(event) =>
event.updatedFiles.firstWhere(
(element) => element.uploadedFileID != null,
orElse: () => null,
) !=
null,
),
removalEventTypes: const {EventType.unarchived},
forceReloadEvents: [
Bus.instance.on<FilesUpdatedEvent>().where(
(event) =>
event.updatedFiles.firstWhere(
(element) => element.uploadedFileID != null,
orElse: () => null,
) !=
null,
),
],
tagPrefix: tagPrefix,
selectedFiles: _selectedFiles,
initialFiles: null,
footer: const SizedBox(height: 120),
);
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(50.0),
child: GalleryAppBarWidget(
appBarType,
locationAndFiles.location,
_selectedFiles,
),
),
body: Stack(
alignment: Alignment.bottomCenter,
children: [
gallery,
GalleryOverlayWidget(
overlayType,
_selectedFiles,
)
],
),
);
}
}