Home > Mobile >  How to put more than three elements in a listview
How to put more than three elements in a listview

Time:12-12

Currently I need to display more than three elements in a list tile I used leading, title and trailing but I am unable to add an image inbetween the leading and title the current code I have vs the required listtile

return ListTile(
  tileColor: Colors.white,
  shape: RoundedRectangleBorder(

    borderRadius: BorderRadius.circular(10),
  ),
  leading:
      Icon(
    isSaved ? Icons.favorite : Icons.favorite_border,
    color: isSaved ? Colors.red : null,),
  title: Text(nameData.getName(index)),
  trailing: Text(
    nameData.getDate(index),
  ),
);

CodePudding user response:

Try This. I used an icon if you want to use image then replace the icon and use your image

 return ListTile(
            tileColor: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10),
            ),
            leading: SizedBox(
              height: 30,
              width: 60,
              child: Row(
                children: [
                 Icon(
                    isSaved ? Icons.favorite : Icons.favorite_border,
                    color: isSaved ? Colors.red : null,
                  ),
                  SizedBox(
                    width: 5,
                  ),
                 Icon(
                    isSaved ? Icons.favorite : Icons.favorite_border,
                    color: isSaved ? Colors.red : null,
                  ),
                ],
              ),
            ),
            title: Text(nameData.getName(index)),
            trailing: Text(
              nameData.getDate(index),
            ),
          );

CodePudding user response:

leading: SizedBox(
  height: 100.0,
  width: 100.0, // fixed width and height
  child: Image.asset(...)
)

  leading: CircleAvatar(
      backgroundImage: AssetImage("..."), // no matter how big it is, it won't overflow
    ),

If you wanna use rectangle image, you an use

leading: ConstrainedBox(
  constraints: BoxConstraints(
    minWidth: 44,
    minHeight: 44,
    maxWidth: 64,
    maxHeight: 64,
  ),
  child: Image.asset(profileImage, fit: BoxFit.cover),
),
  • Related