简体   繁体   中英

How to remove the divider lines of an ExpansionTile when expanded in Flutter

I have an ExpansionTile within my Drawer widget. When I expand this item, it automatically adds a divider line above and below. I want these divider lines permanently.

So I'd either like to know how to show the ExpansionTile's divider lines always (expanded and unexpanded), or I can add my own divider lines and tell the ExpansionTile to never show divider lines.

Is this possible? Thanks.

you can hide divider lines by wrapping the ExpansionTile widget in Theme Widget,

your code will look like this after you add Theme widget

Theme:(
     data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
     child:ExpansionTile(
         title:...,
         children:[],
     ),
),

check this Github Issue

@RJB, I had the same issue, I resolved wrapping the ExpansionTile with a column, like this:

Theme(
  data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
  child: Column(
    children: [
      ExpansionTile(
        title: Text(
         'My title',
          style: const TextStyle(
            fontWeight: FontWeight.bold,
          ),
        ),
        trailing: Icon(
          _showContent
              ? Icons.expand_less_rounded
              : Icons.expand_more_rounded,
        ),
        onExpansionChanged: (bool expanded) {
          setState(() => _showContent = expanded);
        },
        children: <Widget>[
          Text('My content'),
        ],
      ),
      const Divider(
        color: Colors.amber,
        thickness: 1,
        height: 0,
      )
    ],
  ),
);

I know it isn't pretty, but I could't find an Expansion component that I could personalize every aspect of its appearance.

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