Skip to content

Commit a0e91bf

Browse files
authored
Update Flutter Gallery to use new asset api for package assets (flutter#12254)
1 parent 49ba974 commit a0e91bf

File tree

13 files changed

+316
-116
lines changed

13 files changed

+316
-116
lines changed

examples/flutter_gallery/lib/demo/animation/sections.dart

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,33 @@ const Color _tomato = const Color(0xFFF95B57);
1212
const Color _mySin = const Color(0xFFF3A646);
1313
const Color _deepCerise = const Color(0xFFD93F9B);
1414

15+
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
16+
1517
class SectionDetail {
16-
const SectionDetail({ this.title, this.subtitle, this.imageAsset });
18+
const SectionDetail({
19+
this.title,
20+
this.subtitle,
21+
this.imageAsset,
22+
this.imageAssetPackage,
23+
});
1724
final String title;
1825
final String subtitle;
1926
final String imageAsset;
27+
final String imageAssetPackage;
2028
}
2129

2230
class Section {
23-
const Section({ this.title, this.backgroundAsset, this.leftColor, this.rightColor, this.details });
31+
const Section({
32+
this.title,
33+
this.backgroundAsset,
34+
this.backgroundAssetPackage,
35+
this.leftColor,
36+
this.rightColor,
37+
this.details,
38+
});
2439
final String title;
2540
final String backgroundAsset;
41+
final String backgroundAssetPackage;
2642
final Color leftColor;
2743
final Color rightColor;
2844
final List<SectionDetail> details;
@@ -44,51 +60,60 @@ class Section {
4460
// image SectionDetails in the allSections list.
4561

4662
const SectionDetail _eyeglassesDetail = const SectionDetail(
47-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/sunnies.png',
63+
imageAsset: 'shrine/products/sunnies.png',
64+
imageAssetPackage: _kGalleryAssetsPackage,
4865
title: 'Flutter enables interactive animation',
4966
subtitle: '3K views - 5 days',
5067
);
5168

5269
const SectionDetail _eyeglassesImageDetail = const SectionDetail(
53-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/sunnies.png',
70+
imageAsset: 'shrine/products/sunnies.png',
71+
imageAssetPackage: _kGalleryAssetsPackage,
5472
);
5573

5674
const SectionDetail _seatingDetail = const SectionDetail(
57-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/lawn_chair.png',
75+
imageAsset: 'shrine/products/lawn_chair.png',
76+
imageAssetPackage: _kGalleryAssetsPackage,
5877
title: 'Flutter enables interactive animation',
5978
subtitle: '3K views - 5 days',
6079
);
6180

6281
const SectionDetail _seatingImageDetail = const SectionDetail(
63-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/lawn_chair.png',
82+
imageAsset: 'shrine/products/lawn_chair.png',
83+
imageAssetPackage: _kGalleryAssetsPackage,
6484
);
6585

6686
const SectionDetail _decorationDetail = const SectionDetail(
67-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/lipstick.png',
87+
imageAsset: 'shrine/products/lipstick.png',
88+
imageAssetPackage: _kGalleryAssetsPackage,
6889
title: 'Flutter enables interactive animation',
6990
subtitle: '3K views - 5 days',
7091
);
7192

7293
const SectionDetail _decorationImageDetail = const SectionDetail(
73-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/lipstick.png',
94+
imageAsset: 'shrine/products/lipstick.png',
95+
imageAssetPackage: _kGalleryAssetsPackage,
7496
);
7597

7698
const SectionDetail _protectionDetail = const SectionDetail(
77-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/helmet.png',
99+
imageAsset: 'shrine/products/helmet.png',
100+
imageAssetPackage: _kGalleryAssetsPackage,
78101
title: 'Flutter enables interactive animation',
79102
subtitle: '3K views - 5 days',
80103
);
81104

82105
const SectionDetail _protectionImageDetail = const SectionDetail(
83-
imageAsset: 'packages/flutter_gallery_assets/shrine/products/helmet.png',
106+
imageAsset: 'shrine/products/helmet.png',
107+
imageAssetPackage: _kGalleryAssetsPackage,
84108
);
85109

86110
final List<Section> allSections = <Section>[
87111
const Section(
88112
title: 'EYEGLASSES',
89113
leftColor: _mediumPurple,
90114
rightColor: _mariner,
91-
backgroundAsset: 'packages/flutter_gallery_assets/shrine/products/sunnies.png',
115+
backgroundAsset: 'shrine/products/sunnies.png',
116+
backgroundAssetPackage: _kGalleryAssetsPackage,
92117
details: const <SectionDetail>[
93118
_eyeglassesDetail,
94119
_eyeglassesImageDetail,
@@ -102,7 +127,8 @@ final List<Section> allSections = <Section>[
102127
title: 'SEATING',
103128
leftColor: _tomato,
104129
rightColor: _mediumPurple,
105-
backgroundAsset: 'packages/flutter_gallery_assets/shrine/products/lawn_chair.png',
130+
backgroundAsset: 'shrine/products/lawn_chair.png',
131+
backgroundAssetPackage: _kGalleryAssetsPackage,
106132
details: const <SectionDetail>[
107133
_seatingDetail,
108134
_seatingImageDetail,
@@ -116,7 +142,8 @@ final List<Section> allSections = <Section>[
116142
title: 'DECORATION',
117143
leftColor: _mySin,
118144
rightColor: _tomato,
119-
backgroundAsset: 'packages/flutter_gallery_assets/shrine/products/lipstick.png',
145+
backgroundAsset: 'shrine/products/lipstick.png',
146+
backgroundAssetPackage: _kGalleryAssetsPackage,
120147
details: const <SectionDetail>[
121148
_decorationDetail,
122149
_decorationImageDetail,
@@ -130,7 +157,8 @@ final List<Section> allSections = <Section>[
130157
title: 'PROTECTION',
131158
leftColor: Colors.white,
132159
rightColor: _tomato,
133-
backgroundAsset: 'packages/flutter_gallery_assets/shrine/products/helmet.png',
160+
backgroundAsset: 'shrine/products/helmet.png',
161+
backgroundAssetPackage: _kGalleryAssetsPackage,
134162
details: const <SectionDetail>[
135163
_protectionDetail,
136164
_protectionImageDetail,

examples/flutter_gallery/lib/demo/animation/widgets.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SectionCard extends StatelessWidget {
3535
),
3636
child: new Image.asset(
3737
section.backgroundAsset,
38+
package: section.backgroundAssetPackage,
3839
color: const Color.fromRGBO(255, 255, 255, 0.075),
3940
colorBlendMode: BlendMode.modulate,
4041
fit: BoxFit.cover,
@@ -130,7 +131,10 @@ class SectionDetailView extends StatelessWidget {
130131
decoration: new BoxDecoration(
131132
borderRadius: new BorderRadius.circular(6.0),
132133
image: new DecorationImage(
133-
image: new AssetImage(detail.imageAsset),
134+
image: new AssetImage(
135+
detail.imageAsset,
136+
package: detail.imageAssetPackage,
137+
),
134138
fit: BoxFit.cover,
135139
alignment: FractionalOffset.center,
136140
),

examples/flutter_gallery/lib/demo/contacts_demo.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class ContactsDemoState extends State<ContactsDemo> {
156156
fit: StackFit.expand,
157157
children: <Widget>[
158158
new Image.asset(
159-
'packages/flutter_gallery_assets/ali_connors.jpg',
159+
'ali_connors.jpg',
160+
package: 'flutter_gallery_assets',
160161
fit: BoxFit.cover,
161162
height: _appBarHeight,
162163
),

examples/flutter_gallery/lib/demo/material/cards_demo.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77

8+
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
9+
810
class TravelDestination {
9-
const TravelDestination({ this.assetName, this.title, this.description });
11+
const TravelDestination({
12+
this.assetName,
13+
this.assetPackage,
14+
this.title,
15+
this.description,
16+
});
1017

1118
final String assetName;
19+
final String assetPackage;
1220
final String title;
1321
final List<String> description;
1422

@@ -17,7 +25,8 @@ class TravelDestination {
1725

1826
final List<TravelDestination> destinations = <TravelDestination>[
1927
const TravelDestination(
20-
assetName: 'packages/flutter_gallery_assets/top_10_australian_beaches.jpg',
28+
assetName: 'top_10_australian_beaches.jpg',
29+
assetPackage: _kGalleryAssetsPackage,
2130
title: 'Top 10 Australian beaches',
2231
description: const <String>[
2332
'Number 10',
@@ -26,7 +35,8 @@ final List<TravelDestination> destinations = <TravelDestination>[
2635
],
2736
),
2837
const TravelDestination(
29-
assetName: 'packages/flutter_gallery_assets/kangaroo_valley_safari.jpg',
38+
assetName: 'kangaroo_valley_safari.jpg',
39+
assetPackage: _kGalleryAssetsPackage,
3040
title: 'Kangaroo Valley Safari',
3141
description: const <String>[
3242
'2031 Moss Vale Road',
@@ -65,6 +75,7 @@ class TravelDestinationItem extends StatelessWidget {
6575
new Positioned.fill(
6676
child: new Image.asset(
6777
destination.assetName,
78+
package: destination.assetPackage,
6879
fit: BoxFit.cover,
6980
),
7081
),

examples/flutter_gallery/lib/demo/material/drawer_demo.dart

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import 'package:flutter/material.dart';
66

7-
const String _kAsset0 = 'packages/flutter_gallery_assets/shrine/vendors/zach.jpg';
8-
const String _kAsset1 = 'packages/flutter_gallery_assets/shrine/vendors/16c477b.jpg';
9-
const String _kAsset2 = 'packages/flutter_gallery_assets/shrine/vendors/sandra-adams.jpg';
7+
const String _kAsset0 = 'shrine/vendors/zach.jpg';
8+
const String _kAsset1 = 'shrine/vendors/16c477b.jpg';
9+
const String _kAsset2 = 'shrine/vendors/sandra-adams.jpg';
10+
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
1011

1112
class DrawerDemo extends StatefulWidget {
1213
static const String routeName = '/material/drawer';
@@ -93,10 +94,25 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
9394
new UserAccountsDrawerHeader(
9495
accountName: const Text('Zach Widget'),
9596
accountEmail: const Text('zach.widget@example.com'),
96-
currentAccountPicture: const CircleAvatar(backgroundImage: const AssetImage(_kAsset0)),
97+
currentAccountPicture: const CircleAvatar(
98+
backgroundImage: const AssetImage(
99+
_kAsset0,
100+
package: _kGalleryAssetsPackage,
101+
),
102+
),
97103
otherAccountsPictures: const <Widget>[
98-
const CircleAvatar(backgroundImage: const AssetImage(_kAsset1)),
99-
const CircleAvatar(backgroundImage: const AssetImage(_kAsset2)),
104+
const CircleAvatar(
105+
backgroundImage: const AssetImage(
106+
_kAsset1,
107+
package: _kGalleryAssetsPackage,
108+
),
109+
),
110+
const CircleAvatar(
111+
backgroundImage: const AssetImage(
112+
_kAsset2,
113+
package: _kGalleryAssetsPackage,
114+
),
115+
),
100116
],
101117
onDetailsPressed: () {
102118
_showDrawerContents = !_showDrawerContents;
@@ -167,7 +183,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
167183
decoration: const BoxDecoration(
168184
shape: BoxShape.circle,
169185
image: const DecorationImage(
170-
image: const AssetImage(_kAsset0),
186+
image: const AssetImage(
187+
_kAsset0,
188+
package: _kGalleryAssetsPackage,
189+
),
171190
),
172191
),
173192
),

0 commit comments

Comments
 (0)