Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

my project don't work because of flutter image. I tried everythig please help me

i have been trying to fix it for weeks but i cannot add a image why?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i have trying to change path part but it didn’t work it

maindart:

import 'package:flutter/material.dart';

import 'dashboard.dart';

void main() => runApp(MyApp());

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'my flutter app',
      themeMode: ThemeMode.system,
      debugShowCheckedModeBanner: false,
      home: DashBoard(),
    );
  }
}

dashboard:

import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: Image.asset(
          "ghibli.jpg",
          width: 300,
          height: 400,
        ));
  }
}

>Solution :

add your image path to the pubspec.yaml file.

flutter:
  uses-material-design: true

  assets:
    - images/ghibli.jpg

then use it like:

body: Image.asset(
    "images/ghibli.jpg",
     width: 300,
     height: 400,
  ));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading