skip to Main Content

Trying to set image for icon in flutter but not working. So, How to set path for ImageIcon in ListTile.

This line is not working:

leading: ImageIcon(AssetImage('images/abt.png'), size: 25),
        GestureDetector(
            onTap: ()
            {
              Navigator.push(context, MaterialPageRoute(builder: (c)=> AboutScreen()));
            },
            child: const ListTile(
              tileColor: Colors.blue,
              leading: ImageIcon(AssetImage('images/abt.png'), size: 25),
              title: Text(
                "About",
                style: TextStyle(
                    color: Colors.black
                ),
              ),
            ),
          ),

2

Answers


  1. Update the pubspec.yaml file.

    assets:  
        - images/
        - images/abt.png  
    

    Flutter uses the pubspec.yaml file, located at the root of your project, to identify assets required by an app. Read here how to specify assets and images in Flutter.

    Login or Signup to reply.
  2. You possibly have not uncommented these lines in pubspec.yaml

    # assets:
    #  - images/a_dot_burr.jpeg
    #  - images/a_dot_ham.jpeg
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search