text stringlengths 1 372 |
|---|
<topic_start> |
bundling of package assets |
if the desired asset is specified in the pubspec.yaml |
file of the package, it’s bundled automatically with the |
application. in particular, assets used by the package |
itself must be specified in its pubspec.yaml. |
a package can also choose to have assets in its lib/ |
folder that are not specified in its pubspec.yaml file. |
in this case, for those images to be bundled, |
the application has to specify which ones to include in its |
pubspec.yaml. for instance, a package named fancy_backgrounds |
could have the following files: |
to include, say, the first image, the pubspec.yaml of the |
application should specify it in the assets section: |
the lib/ is implied, |
so it should not be included in the asset path. |
if you are developing a package, to load an asset within the package, specify it in the pubspec.yaml of the package: |
to load the image within your package, use: |
<topic_end> |
<topic_start> |
sharing assets with the underlying platform |
flutter assets are readily available to platform code |
using the AssetManager on android and NSBundle on iOS. |
<topic_end> |
<topic_start> |
loading flutter assets in android |
on android the assets are available through the |
AssetManager API. the lookup key used in, |
for instance openFd, is obtained from |
lookupKeyForAsset on PluginRegistry.Registrar or |
getLookupKeyForAsset on FlutterView. |
PluginRegistry.Registrar is available when developing a plugin |
while FlutterView would be the choice when developing an |
app including a platform view. |
as an example, suppose you have specified the following |
in your pubspec.yaml |
this reflects the following structure in your flutter app. |
to access icons/heart.png from your java plugin code, |
do the following: |
<topic_end> |
<topic_start> |
loading flutter assets in iOS |
on iOS the assets are available through the mainBundle. |
the lookup key used in, for instance pathForResource:ofType:, |
is obtained from lookupKeyForAsset or lookupKeyForAsset:fromPackage: |
on FlutterPluginRegistrar, or lookupKeyForAsset: or |
lookupKeyForAsset:fromPackage: on FlutterViewController. |
FlutterPluginRegistrar is available when developing |
a plugin while FlutterViewController would be the choice |
when developing an app including a platform view. |
as an example, suppose you have the flutter setting from above. |
to access icons/heart.png from your Objective-C plugin code you |
would do the following: |
to access icons/heart.png from your swift app you |
would do the following: |
for a more complete example, see the implementation of the |
flutter video_player plugin on pub.dev. |
the ios_platform_images plugin on pub.dev wraps |
up this logic in a convenient category. you fetch |
an image as follows: |
Objective-C: |
swift: |
<topic_end> |
<topic_start> |
loading iOS images in flutter |
when implementing flutter by |
adding it to an existing iOS app, |
you might have images hosted in iOS that you |
want to use in flutter. to accomplish |
that, use the ios_platform_images plugin |
available on pub.dev. |
<topic_end> |
<topic_start> |
platform assets |
there are other occasions to work with assets in the |
platform projects directly. below are two common cases |
where assets are used before the flutter framework is |
loaded and running. |
<topic_end> |
<topic_start> |
updating the app icon |
updating a flutter application’s launch icon works |
the same way as updating launch icons in native |
android or iOS applications. |
<topic_end> |
<topic_start> |
android |
in your flutter project’s root directory, navigate to |
.../android/app/src/main/res. the various bitmap resource |
folders such as mipmap-hdpi already contain placeholder |
images named ic_launcher.png. replace them with your |
desired assets respecting the recommended icon size per |
screen density as indicated by the android developer guide. |
info note |
if you rename the .png files, you must also update the |
corresponding name in your AndroidManifest.xml’s |
<application> tag’s android:icon attribute. |
<topic_end> |
<topic_start> |
iOS |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.