i've got a problem with my flutter project. I've added some images, sounds and a json file to pubspec.yaml like this:
flutter:
uses-material-design: true
assets:
- assets/
- assets/images/
- assets/audio/
The json is in assets/, the background and some icons in assets/images/.
When running flutter run everything works fine. When running flutter build and install the apk on device, the background is available, the icons are not.
Example output:
I/flutter (20572): Image provider: AssetImage(bundle: null, name: "assets/images/background.png")
I/flutter (20572): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#16f51(), name:
I/flutter (20572): "assets/images/background.png", scale: 1.0)
I/flutter (20572): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (20572): Another exception was thrown: Unable to load asset: assets/images/Soundboard Max.png
My implementation looks like this:
class SoundboardGrid extends StatelessWidget {
SoundboardGrid({
Key key,
@required this.sounds,
}) : super(key: key);
final List<Sound> sounds;
final Player audioPlayer = Player();
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.png'),
fit: BoxFit.cover,
),
),
child: GridView.count(
scrollDirection: Axis.vertical,
crossAxisCount: 4,
childAspectRatio: 0.8,
children: List.generate(
sounds.length,
(index) {
return Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Align(
alignment: Alignment.center,
child: GestureDetector(
onTap: () {
audioPlayer.play(sounds[index].filename);
},
child: Container(
child: Padding(
padding: EdgeInsets.fromLTRB(12, 12, 12, 3),
child: Image.asset('assets/images/Soundboard ${sounds[index].speaker}.png')
),
),
),
),
Container(
child: Text(
sounds[index].filename,
style: TextStyle(color: Colors.white, fontSize: 11),
textAlign: TextAlign.center,
),
alignment: Alignment.bottomCenter,
)
],
);
},
),
),
);
}
}
Using the Imageprovider instead of the "Image.asset Widget" gives the same result.