Skip to content

Commit

Permalink
Add hero animation to images
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Amin committed Aug 2, 2019
1 parent 4fce92d commit 7a76cfd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/screens/home/widgets/explore/explore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ExploreProductList extends StatelessWidget {
itemCount: products.length,
itemBuilder: (context, index) => ExploreProductCard(
product: products[index],
index: index,
),
));
}
Expand Down
10 changes: 7 additions & 3 deletions lib/screens/home/widgets/explore/explore_product_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'package:shoptronics/common/product_card.dart';
import 'package:shoptronics/data_models/product.dart';

class ExploreProductCard extends StatelessWidget {
ExploreProductCard({Key key, this.product}) : super(key: key);
ExploreProductCard({Key key, this.product, this.index}) : super(key: key);

final num index;
final Product product;
Color textColor() {
switch (product.color) {
Expand Down Expand Up @@ -45,8 +46,11 @@ class ExploreProductCard extends StatelessWidget {
Container(
height: 115,
alignment: Alignment.topCenter,
child: Image.asset(
product.photoUrl,
child: Hero(
tag: product.photoUrl + index.toString(),
child: Image.asset(
product.photoUrl,
),
),
),
Container(
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home/widgets/hot_items/hot_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class HotProductList extends StatelessWidget {
itemCount: products.length,
itemBuilder: (context, index) => HotProductCard(
product: products[index],
index: index,
),
));
}
Expand Down
11 changes: 7 additions & 4 deletions lib/screens/home/widgets/hot_items/hot_product_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:shoptronics/common/product_card.dart';
import 'package:shoptronics/data_models/product.dart';

class HotProductCard extends StatelessWidget {
HotProductCard({Key key, this.product}) : super(key: key);

HotProductCard({Key key, this.product, this.index}) : super(key: key);
final num index;
final Product product;

@override
Expand All @@ -21,8 +21,11 @@ class HotProductCard extends StatelessWidget {
width: 160,
height: 140,
alignment: Alignment.centerLeft,
child: Image.asset(
product.photoUrl,
child: Hero(
tag: product.photoUrl + index.toString(),
child: Image.asset(
product.photoUrl,
),
),
),
],
Expand Down
17 changes: 10 additions & 7 deletions lib/screens/product/widgets/image_page_view/image_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class ImagePageView extends StatefulWidget {
class _ImagePageViewState extends State<ImagePageView> {
@override
Widget build(BuildContext context) {
return PageView(
physics: BouncingScrollPhysics(),
children: <Widget>[
Image.asset("assets/images/product1.png"),
Image.asset("assets/images/product1.png"),
Image.asset("assets/images/product1.png"),
],
return Hero(
tag: "assets/images/product1.png0",
child: PageView(
physics: BouncingScrollPhysics(),
children: <Widget>[
Image.asset("assets/images/product1.png"),
Image.asset("assets/images/product1.png"),
Image.asset("assets/images/product1.png"),
],
),
);
}
}

0 comments on commit 7a76cfd

Please sign in to comment.