Remove the extended page view nonsense
This commit is contained in:
parent
697f6ded7a
commit
df1240fd0c
3 changed files with 37 additions and 49 deletions
|
@ -1,7 +0,0 @@
|
|||
import 'package:photos/models/photo.dart';
|
||||
|
||||
class PhotoOpenedEvent {
|
||||
final Photo photo;
|
||||
|
||||
PhotoOpenedEvent(this.photo);
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:like_button/like_button.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/photo_opened_event.dart';
|
||||
import 'package:photos/core/cache/image_cache.dart';
|
||||
import 'package:photos/favorite_photos_repository.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/ui/extents_page_view.dart';
|
||||
import 'package:photos/ui/zoomable_image.dart';
|
||||
import 'package:photos/utils/date_time_util.dart';
|
||||
import 'package:photos/utils/share_util.dart';
|
||||
|
@ -34,12 +32,6 @@ class _DetailPageState extends State<DetailPage> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Bus.instance.fire(PhotoOpenedEvent(null));
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_logger.info("Opening " +
|
||||
|
@ -60,7 +52,7 @@ class _DetailPageState extends State<DetailPage> {
|
|||
}
|
||||
|
||||
Widget _buildPageView() {
|
||||
return ExtentsPageView.extents(
|
||||
return PageView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final photo = _photos[index];
|
||||
final image = ZoomableImage(
|
||||
|
@ -71,24 +63,47 @@ class _DetailPageState extends State<DetailPage> {
|
|||
});
|
||||
},
|
||||
);
|
||||
if (index == _selectedIndex) {
|
||||
Bus.instance.fire(PhotoOpenedEvent(photo));
|
||||
}
|
||||
_preloadPhotos(index);
|
||||
return image;
|
||||
},
|
||||
onPageChanged: (int index) {
|
||||
onPageChanged: (index) {
|
||||
_selectedIndex = index;
|
||||
Bus.instance.fire(PhotoOpenedEvent(widget.photos[index]));
|
||||
_preloadPhotos(index);
|
||||
},
|
||||
physics: _shouldDisableScroll
|
||||
? NeverScrollableScrollPhysics()
|
||||
: PageScrollPhysics(),
|
||||
controller: PageController(initialPage: _selectedIndex),
|
||||
itemCount: _photos.length,
|
||||
extents: 1,
|
||||
);
|
||||
}
|
||||
|
||||
void _preloadPhotos(int index) {
|
||||
if (index > 0) {
|
||||
_preloadPhoto(_photos[index - 1]);
|
||||
}
|
||||
if (index < _photos.length - 1) {
|
||||
_preloadPhoto(_photos[index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void _preloadPhoto(Photo photo) {
|
||||
if (photo.localId == null) {
|
||||
photo.getBytes().then((data) {
|
||||
BytesLruCache.put(photo, data);
|
||||
});
|
||||
} else {
|
||||
final cachedFile = FileLruCache.get(photo);
|
||||
if (cachedFile == null) {
|
||||
photo.getAsset().then((asset) {
|
||||
asset.file.then((file) {
|
||||
FileLruCache.put(photo, file);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppBar _buildAppBar() {
|
||||
final actions = List<Widget>();
|
||||
if (_photos[_selectedIndex].localId != null) {
|
||||
|
|
|
@ -4,9 +4,8 @@ import 'dart:collection';
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/events/event.dart';
|
||||
import 'package:photos/events/photo_opened_event.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/ui/detail_page.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
|
@ -39,6 +38,7 @@ class Gallery extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _GalleryState extends State<Gallery> {
|
||||
final Logger _logger = Logger("Gallery");
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final List<List<Photo>> _collatedPhotos = List<List<Photo>>();
|
||||
|
||||
|
@ -47,18 +47,10 @@ class _GalleryState extends State<Gallery> {
|
|||
Set<Photo> _selectedPhotos = HashSet<Photo>();
|
||||
List<Photo> _photos;
|
||||
RefreshController _refreshController = RefreshController();
|
||||
StreamSubscription<PhotoOpenedEvent> _photoOpenEventSubscription;
|
||||
Photo _openedPhoto;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_requiresLoad = true;
|
||||
_photoOpenEventSubscription =
|
||||
Bus.instance.on<PhotoOpenedEvent>().listen((event) {
|
||||
setState(() {
|
||||
_openedPhoto = event.photo;
|
||||
});
|
||||
});
|
||||
if (widget.reloadEvent != null) {
|
||||
widget.reloadEvent.listen((event) {
|
||||
setState(() {
|
||||
|
@ -69,12 +61,6 @@ class _GalleryState extends State<Gallery> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_photoOpenEventSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_requiresLoad) {
|
||||
|
@ -173,15 +159,6 @@ class _GalleryState extends State<Gallery> {
|
|||
}
|
||||
|
||||
Widget _buildPhoto(BuildContext context, Photo photo) {
|
||||
Widget thumbnail;
|
||||
if (_openedPhoto == null || _openedPhoto == photo) {
|
||||
thumbnail = Hero(
|
||||
tag: photo.generatedId.toString(),
|
||||
child: ThumbnailWidget(photo),
|
||||
);
|
||||
} else {
|
||||
thumbnail = ThumbnailWidget(photo);
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (_selectedPhotos.isNotEmpty) {
|
||||
|
@ -201,7 +178,10 @@ class _GalleryState extends State<Gallery> {
|
|||
? Border.all(width: 4.0, color: Colors.blue)
|
||||
: null,
|
||||
),
|
||||
child: thumbnail,
|
||||
child: Hero(
|
||||
tag: photo.generatedId.toString(),
|
||||
child: ThumbnailWidget(photo),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue