Dolphin
Dolphin

Reputation: 38601

How to tweak ListTile width in flutter

Now I am using ListTile like this in flutter:

ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                  color: Colors.white,
                  child: ListTile(
                    leading: Icon(Feather.settings),
                    title: Text("设置"),
                    onTap: () async {
                      Widget page = CustomSetting();
                      Navigator.push(
                        context,
                        MaterialPageRoute(builder: (context) => page),
                      );
                    },
                  ))
          )

this is the result now:

enter image description here

Now I want the ListTile not fill full of width of screen, keep left side and right side with some gap, but when I tweak the width of Container it does not have any change, what should I do to make it work? the effect may like this:

enter image description here

I added padding like this but still not work:

ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                  color: Colors.white,
                  //margin: const EdgeInsets.only(left: 20.0, right: 20.0),
                  child: Padding(
                      padding: EdgeInsets.symmetric(horizontal: 40),
                      child: ListTile(
                        leading: Icon(Feather.settings),
                        title: Text("设置"),
                        onTap: () async {
                          Widget page = CustomSetting();
                          Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) => page),
                          );
                        },
                      ))))

Upvotes: 0

Views: 482

Answers (2)

Deepak Lohmod
Deepak Lohmod

Reputation: 2272

wrap your ClipRRect with padding

Padding(
          padding: EdgeInsets.only(left:10,right:10),
        child:ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                  color: Colors.white,
                  child: ListTile(
                    leading: Icon(Icons.settings),
                    title: Text("设置"),
                  ))
          ),
        ),

Upvotes: 1

Saisha
Saisha

Reputation: 94

Enclose it in a Padding widget.

ClipRRect(
    borderRadius: BorderRadius.circular(10),
    child: Container(
        color: Colors.white,
        child: Padding(
            padding: EdgeInsets.fromLTRB(100, 30, 100, 30),
            child: ListTile(
                leading: Icon(Feather.settings),
                title: Text("设置"),
                onTap: () async {
                Widget page = CustomSetting();
                Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => page),
                    );
                }, 
                )// ListTile
            ) // Padding
        ) // Container
) //  ClipRRect 

Upvotes: 1

Related Questions