skip to Main Content

I have ListTile inside padding. I need to change the padding area color. How can I change it?enter image description here

SliverList(
            delegate: SliverChildBuilderDelegate(
                  (context, index) => Card(
                elevation: 1,
                color: MyColors.white,
                margin: const EdgeInsets.symmetric(vertical: 0),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ListTile(
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
                        tileColor: Color(0xFFFCF9E8),
                        leading: Image(image: AssetImage(_allUsers[index]['icon']),height: 30,width: 30,),
                        title: Text(_allUsers[index]['name']),
                        subtitle: Text('${_allUsers[index]["generic"]}'),
                        trailing: Text('${_allUsers[index]["unit_price"]}'),
                  ),
                ),
              ),
              childCount: _allUsers.length,
            ),
          ),

2

Answers


  1. Use Container instead of Padding and give padding and color to it like this:

    Container(
                    color: Colors.red, //color
                    padding: const EdgeInsets.all(8.0), //your padding 
                    child:ListTile(
                            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
                            tileColor: Color(0xFFFCF9E8),
                            leading: Image(image: AssetImage(_allUsers[index]['icon']),height: 30,width: 30,),
                            title: Text(_allUsers[index]['name']),
                            subtitle: Text('${_allUsers[index]["generic"]}'),
                            trailing: Text('${_allUsers[index]["unit_price"]}'),
                  ),
    
    Login or Signup to reply.
  2. you can use ColoredBox for that:

    ColoredBox(
      color: MyColors.white,
      child:SliverList(
                delegate: SliverChildBuilderDelegate(
                      (context, index) => Card(
                    elevation: 1,
                    color: MyColors.white,
                    margin: const EdgeInsets.symmetric(vertical: 0),
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: ListTile(
                            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
                            tileColor: Color(0xFFFCF9E8),
                            leading: Image(image: AssetImage(_allUsers[index]['icon']),height: 30,width: 30,),
                            title: Text(_allUsers[index]['name']),
                            subtitle: Text('${_allUsers[index]["generic"]}'),
                            trailing: Text('${_allUsers[index]["unit_price"]}'),
                      ),
                    ),
                  ),
                  childCount: _allUsers.length,
                ),
              ),
      ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search