Commit 2f60932d authored by Viktor Lidholt's avatar Viktor Lidholt

Adds nice photos and hero animations to the Grid gallery demo (#3258)

parent 0f70464e
...@@ -25,3 +25,15 @@ assets: ...@@ -25,3 +25,15 @@ assets:
- packages/flutter_gallery_assets/jumpingjack.png - packages/flutter_gallery_assets/jumpingjack.png
- packages/flutter_gallery_assets/grain.png - packages/flutter_gallery_assets/grain.png
- packages/flutter_gallery_assets/fancylines.png - packages/flutter_gallery_assets/fancylines.png
- packages/flutter_gallery_assets/landscape_0.jpg
- packages/flutter_gallery_assets/landscape_1.jpg
- packages/flutter_gallery_assets/landscape_2.jpg
- packages/flutter_gallery_assets/landscape_3.jpg
- packages/flutter_gallery_assets/landscape_4.jpg
- packages/flutter_gallery_assets/landscape_5.jpg
- packages/flutter_gallery_assets/landscape_6.jpg
- packages/flutter_gallery_assets/landscape_7.jpg
- packages/flutter_gallery_assets/landscape_8.jpg
- packages/flutter_gallery_assets/landscape_9.jpg
- packages/flutter_gallery_assets/landscape_10.jpg
- packages/flutter_gallery_assets/landscape_11.jpg
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:collection';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -14,19 +15,80 @@ enum GridDemoTileStyle { ...@@ -14,19 +15,80 @@ enum GridDemoTileStyle {
} }
class Photo { class Photo {
const Photo({ this.assetName }); const Photo({ this.assetName, this.title, this.caption });
final String assetName; final String assetName;
String get title => 'Safari'; final String title;
String get caption => 'March 2015'; final String caption;
bool get isValid => assetName != null; bool get isValid => assetName != null;
} }
final List<Photo> photos = new List<Photo>.generate(16, (int index) { final List<Photo> photos = <Photo>[
return const Photo(assetName: 'packages/flutter_gallery_assets/kangaroo_valley_safari.png'); const Photo(
}); assetName: 'packages/flutter_gallery_assets/landscape_0.jpg',
title: 'Philippines',
caption: 'Batad rice terraces'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_1.jpg',
title: 'Italy',
caption: 'Ceresole Reale'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_2.jpg',
title: 'Somewhere',
caption: 'Beautiful mountains'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_3.jpg',
title: 'A place',
caption: 'Beautiful hills'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_4.jpg',
title: 'New Zealand',
caption: 'View from the van'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_5.jpg',
title: 'Autumn',
caption: 'The golden season'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_6.jpg',
title: 'Germany',
caption: 'Englischer Garten'
),
const Photo(assetName:
'packages/flutter_gallery_assets/landscape_7.jpg',
title: 'A country',
caption: 'Grass fields'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_8.jpg',
title: 'Mountain country',
caption: 'River forest'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_9.jpg',
title: 'Alpine place',
caption: 'Green hills'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_10.jpg',
title: 'Desert land',
caption: 'Blue skies'
),
const Photo(
assetName: 'packages/flutter_gallery_assets/landscape_11.jpg',
title: 'Narnia',
caption: 'Rocks and rivers'
),
];
const String photoHeroTag = 'Photo';
class GridDemoPhotoItem extends StatelessWidget { class GridDemoPhotoItem extends StatelessWidget {
GridDemoPhotoItem({ Key key, this.photo, this.tileStyle }) : super(key: key) { GridDemoPhotoItem({ Key key, this.photo, this.tileStyle }) : super(key: key) {
...@@ -38,16 +100,26 @@ class GridDemoPhotoItem extends StatelessWidget { ...@@ -38,16 +100,26 @@ class GridDemoPhotoItem extends StatelessWidget {
final GridDemoTileStyle tileStyle; final GridDemoTileStyle tileStyle;
void showPhoto(BuildContext context) { void showPhoto(BuildContext context) {
Key photoKey = new Key(photo.assetName);
Set<Key> mostValuableKeys = new HashSet<Key>();
mostValuableKeys.add(photoKey);
Navigator.push(context, new MaterialPageRoute<Null>( Navigator.push(context, new MaterialPageRoute<Null>(
settings: new RouteSettings(
mostValuableKeys: mostValuableKeys
),
builder: (BuildContext context) { builder: (BuildContext context) {
return new Scaffold( return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text(photo.title) title: new Text(photo.title)
), ),
body: new Material( body: new Material(
child: new AssetImage( child: new Hero(
name: photo.assetName, tag: photoHeroTag,
fit: ImageFit.cover child: new AssetImage(
name: photo.assetName,
fit: ImageFit.cover
)
) )
) )
); );
...@@ -59,9 +131,13 @@ class GridDemoPhotoItem extends StatelessWidget { ...@@ -59,9 +131,13 @@ class GridDemoPhotoItem extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget image = new GestureDetector( final Widget image = new GestureDetector(
onTap: () { showPhoto(context); }, onTap: () { showPhoto(context); },
child: new AssetImage( child: new Hero(
name: photo.assetName, key: new Key(photo.assetName),
fit: ImageFit.cover tag: photoHeroTag,
child: new AssetImage(
name: photo.assetName,
fit: ImageFit.cover
)
) )
); );
......
...@@ -10,4 +10,4 @@ dependencies: ...@@ -10,4 +10,4 @@ dependencies:
path: ../../packages/flutter_sprites path: ../../packages/flutter_sprites
flutter_markdown: flutter_markdown:
path: ../../packages/flutter_markdown path: ../../packages/flutter_markdown
flutter_gallery_assets: '0.0.13' flutter_gallery_assets: '0.0.15'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment