Reputation: 98
I am trying a simple flutter app. It is working fine on web. But on android, images can't load.
this is my pubspec.yaml
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- images/
- gif/
I have images
and gif
folders at root of project.
and I am loading images like this
child: Image(image: AssetImage("/images/abc.jpg"),
or
child: Image(image: AssetImage("/gif/abc.gif"),
This works fine when I run on IDE, but on making android apk, images and gif are not showing.
In android folder, there is no assets directory as well.
I have tired flutter clean
and flutter create .
but no luck.
Upvotes: 0
Views: 1495
Reputation: 181
flutter:
uses-material-design: true
generate: true
assets:
- assets/data/chapters_data.json
String data = await rootBundle.loadString('data/chapters_data.json'); // <-- this won't work for android
List<dynamic> chapters = jsonDecode(data);
To make this work for all the platforms (including Android) use assets/ as prefix. e.g.
String data = await rootBundle.loadString('assets/data/chapters_data.json');
List<dynamic> chapters = jsonDecode(data);
Note that at both places (pubspec.yml and flutter code) the path includes assets/
Upvotes: 0
Reputation: 17
You also need to add following code to AndroidManifest.xml file located at android/app/src/main inside the manifest tag:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Upvotes: 0
Reputation: 326
You need to use like this
Image(image: AssetImage("images/abc.jpg")),
Upvotes: 2