OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import '../mojo/asset_bundle.dart'; | 5 import '../mojo/asset_bundle.dart'; |
6 import 'basic.dart'; | 6 import 'basic.dart'; |
7 | 7 |
8 const String _kAssetBase = '/packages/sky/assets/material-design-icons/'; | 8 AssetBundle _initIconBundle() { |
9 final AssetBundle _iconBundle = new NetworkAssetBundle(Uri.base.resolve(_kAssetB
ase)); | 9 if (rootBundle != null) |
| 10 return rootBundle; |
| 11 const String _kAssetBase = '/packages/sky/assets/material-design-icons/'; |
| 12 return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase)); |
| 13 } |
| 14 |
| 15 final AssetBundle _iconBundle = _initIconBundle(); |
10 | 16 |
11 class Icon extends Component { | 17 class Icon extends Component { |
12 Icon({ String key, this.size, this.type: '' }) : super(key: key); | 18 Icon({ String key, this.size, this.type: '' }) : super(key: key); |
13 | 19 |
14 final int size; | 20 final int size; |
15 final String type; | 21 final String type; |
16 | 22 |
17 Widget build() { | 23 Widget build() { |
18 String category = ''; | 24 String category = ''; |
19 String subtype = ''; | 25 String subtype = ''; |
20 List<String> parts = type.split('/'); | 26 List<String> parts = type.split('/'); |
21 if (parts.length == 2) { | 27 if (parts.length == 2) { |
22 category = parts[0]; | 28 category = parts[0]; |
23 subtype = parts[1]; | 29 subtype = parts[1]; |
24 } | 30 } |
25 // TODO(eseidel): This clearly isn't correct. Not sure what would be. | 31 // TODO(eseidel): This clearly isn't correct. Not sure what would be. |
26 // Should we use the ios images on ios? | 32 // Should we use the ios images on ios? |
27 String density = 'drawable-xxhdpi'; | 33 String density = 'drawable-xxhdpi'; |
28 return new AssetImage( | 34 return new AssetImage( |
29 bundle: _iconBundle, | 35 bundle: _iconBundle, |
30 name: '${category}/${density}/ic_${subtype}_${size}dp.png', | 36 name: '${category}/${density}/ic_${subtype}_${size}dp.png', |
31 size: new Size(size.toDouble(), size.toDouble()) | 37 size: new Size(size.toDouble(), size.toDouble()) |
32 ); | 38 ); |
33 } | 39 } |
34 } | 40 } |
OLD | NEW |