Unable to find assets

21 views Asked by At

I add the image in image folder and enable assets from 'yaml' file in flutter. When i gave the path of assets image and debug the code it shows an Exception that 'Unable to load assets. Assets not found'. In Pubspec.yaml file there is no error at all by enable the assets.. Here is picture of code and output window.

Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: gradientcolors, // reusable gradient colors argument
          begin: startAlignment,
          end: endAlignment,
        ),
      ),
      child: Center(
        child: Image.asset('images/blank-profile-picture-973460_640.png'),
      ),
    );
  }

This is the output image...

I tried to make images directory in the lib directory as well as separately but it doesn't work for both type..

    - images/blank-profile-picture-973460_640.png```
1

There are 1 answers

0
AqibNazir On

I made some changes in my code and now it also not showing the image.. changing in image is as following..

    class _RollingDiceState extends State<RollingDice> {
  var activeDice = 'images/dice-1.png';

  void rollDice() {
    var diceroll = Random().nextInt(6) + 1;
    setState(() {
      activeDice = 'images/dice-$diceroll.png';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Image.asset(
          activeDice, // Passing the value of variable out of function
          scale: 0.5,
        ),
        const SizedBox(
          height: 20,
        ),
        TextButton(
          onPressed:
              rollDice, // Passing pointer as value of a function instead of function call
          style: TextButton.styleFrom(
              foregroundColor: Colors.white,
              textStyle: const TextStyle(fontSize: 20)),
          child: const Text("Roll Dice"),
        ),
      ],
    );
  }
}

[Root Directory are as][1] [1]: https://i.stack.imgur.com/JffNo.png