简体   繁体   中英

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:

在此处输入图像描述

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:

在此处输入图像描述

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),
                          );
                        },
                      ))))

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 

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("设置"),
                  ))
          ),
        ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM