[FIXED] How can i show image in Flutter?

Issue

I build a folder assets and added there my logo.png. But it shows unable to load asset: assets/logo.png . How can I fix this? Below you can find my code.

import ‘package:flutter/material.dart’;
import ‘package:color/color.dart’;

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Container(
         color: Colors.grey[900],
         child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            SizedBox(
              height: 100,
              width: 150,
              child: Image.asset('assets/logo.png'),
            )
          ],
         ),
          )
        ],
      ),
    );
  }
}

image

Solution

You need to add also pubspec.yaml file like this.

flutter:

  uses-material-design: true
  assets:
    - assets/logo.png

Answered By – Yunus Emre Çelik

Answer Checked By – David Goodson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published