Home > database >  Flutter image doesn't appear on screen
Flutter image doesn't appear on screen

Time:09-23

════════ Exception caught by image resource service ════════════════════════════ Unable to load asset: cocacola_bottle.jpg. ════════════════════════════════════════════════════════════════════════════════

This is the yaml file:

flutter:
  assets:
    - assets/

This is the page:

 class Signup extends StatelessWidget {
  const Signup({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        margin: EdgeInsets.all(8.0),
        child: Row(
          // first row first box
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: MediaQuery.of(context).size.width / 2,
              height: 1040,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20.0),
                image: DecorationImage(
                  fit: BoxFit.contain,
                  image: AssetImage('cocacola_bottle.jpg'),
                ),
              ),
            ),
            
          ],
        ),
      ),
    );
  }
}

However, image the doesn't appear on screen.

CodePudding user response:

You have to pass the full path:

image: AssetImage('assets/cocacola_bottle.jpg'),
  • Related