0

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.

2
  • 4
    Do all the missing icon files contain a space in their name? If so, can you remove or replace it with an underscore, for example, and try again? Commented Dec 8, 2019 at 18:10
  • That's it! Thank you very much! Commented Dec 8, 2019 at 18:43

1 Answer 1

0

Try importing individual assets in the pubspec.yaml file. This may work. Put this in assets file below other assets.

- assets/images/Soundboard Max.png

This solution may work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.