skip to Main Content

I know this question has been asked, I looked through all of them and couldn’t find a fix for my code.

This is the pubspec yaml, I think that where I might have the error

name: i_am_rich
description: fuck this shit
version: 1.0.0+1

environment:
  sdk: '>=2.18.4 <3.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - images/

and this is the dart

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.blueGrey,
        appBar: AppBar(
          centerTitle: true,
          title: Text('Shine bright like a'),
          backgroundColor: Colors.blueGrey[900],
        ),
        body: Center(
          child: Image(
            image: AssetImage('images/diamond.png'),
          ),
        ),
      ),
    ),
  );
}

I tried fixing the indentations on the pubspec.yaml, both manually and with tab, and a bunch of stuff from youtube videos, even the course I’m taking (not very good honestly), been trying to fix this for HOURS please help.

3

Answers


  1. do it this way

    first in your pupspect yamel

    # To add assets to your application, add an assets section, like this:
    assets:
      - assets/images/
      - assets/logo/
    

    then refer to it like this:

                              icon: Image.asset(
                                "assets/logo/google_logo.png",
                                fit: BoxFit.contain,
                                width: 24,
                              ),
    

    dont forgot to create an assets folder like this

    enter image description here

    Login or Signup to reply.
  2. = Go to Terminal. and write these commands. "flutter clean " then " flutter pub get " sometimes flutter is like this. and make sure the image file is located in the root of project like the above person’s answer and not inside lib.

    Login or Signup to reply.
  3. Container(
          width: 150,
          height: 150,
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage(
                "images/diamond.png",
              ),
              fit: BoxFit.cover,
            ),
          ),
        ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search