fixed hero tags to animate only between a collection lens and an item from that lens
This commit is contained in:
parent
13dcba9015
commit
ad653e8730
4 changed files with 35 additions and 27 deletions
|
@ -64,6 +64,8 @@ class CollectionLens with ChangeNotifier {
|
|||
|
||||
List<ImageEntry> get sortedEntries => List.unmodifiable(sections.entries.expand((e) => e.value));
|
||||
|
||||
Object heroTag(ImageEntry entry) => '$hashCode${entry.uri}';
|
||||
|
||||
void sort(SortFactor sortFactor) {
|
||||
this.sortFactor = sortFactor;
|
||||
updateSections();
|
||||
|
|
|
@ -44,6 +44,7 @@ class SectionSliver extends StatelessWidget {
|
|||
child: Thumbnail(
|
||||
entry: entry,
|
||||
extent: mqWidth / columnCount,
|
||||
heroTag: collection.heroTag(entry),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
|||
class Thumbnail extends StatelessWidget {
|
||||
final ImageEntry entry;
|
||||
final double extent;
|
||||
final Object heroTag;
|
||||
|
||||
static final Color borderColor = Colors.grey.shade700;
|
||||
static const double borderWidth = .5;
|
||||
|
@ -16,6 +17,7 @@ class Thumbnail extends StatelessWidget {
|
|||
Key key,
|
||||
@required this.entry,
|
||||
@required this.extent,
|
||||
this.heroTag,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -26,8 +28,16 @@ class Thumbnail extends StatelessWidget {
|
|||
width: 50,
|
||||
height: 50,
|
||||
builder: (bytes) {
|
||||
return Hero(
|
||||
tag: entry.uri,
|
||||
final image = Image.memory(
|
||||
bytes,
|
||||
width: extent,
|
||||
height: extent,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
return heroTag == null
|
||||
? image
|
||||
: Hero(
|
||||
tag: heroTag,
|
||||
flightShuttleBuilder: (
|
||||
BuildContext flightContext,
|
||||
Animation<double> animation,
|
||||
|
@ -46,12 +56,7 @@ class Thumbnail extends StatelessWidget {
|
|||
);
|
||||
});
|
||||
},
|
||||
child: Image.memory(
|
||||
bytes,
|
||||
width: extent,
|
||||
height: extent,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
child: image,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -80,7 +80,7 @@ class ImagePageState extends State<ImagePage> with AutomaticKeepAliveClientMixin
|
|||
),
|
||||
backgroundDecoration: backgroundDecoration,
|
||||
heroAttributes: PhotoViewHeroAttributes(
|
||||
tag: entry.uri,
|
||||
tag: widget.collection.heroTag(entry),
|
||||
transitionOnUserGestures: true,
|
||||
),
|
||||
scaleStateChangedCallback: scaleStateChangedCallback,
|
||||
|
|
Loading…
Reference in a new issue