MOmo
MOmo

Reputation: 15

Flutter image doesn't appear on screen

════════ 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.

Upvotes: 0

Views: 28

Answers (1)

Ozan Taskiran
Ozan Taskiran

Reputation: 3552

You have to pass the full path:

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

Upvotes: 1

Related Questions