62

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.

6 Answers 6

151

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

Sign up to request clarification or add additional context in comments.

4 Comments

How do you always show the divider lines, which was included in the question?
@RJB is a bug that show horizontal lines on top and bottom of your ExpansionTile once is opened....it was luckily resolved by Dasunx answer =).
Ugly, but works like a charm. The aesthetic results outweigh the code ugliness :)
I'm wonder why dividerTheme: DividerThemeData( color: Colors.transparent,) did not work.
71

Another option is that instead of wrapping the ExpansionTile widget with Theme, you can pass the shape directly to ExpansionTile as follows:

ExpansionTile(
  // ...
  shape: Border(),
)

4 Comments

This is the only solution that fixes the annoying border line.
It works for when set collapsedShape: Border(), inside ExpansionTileThemeData
This should be marked as the right solution! The other solution where the divider color is set to transparent doesn't remove the divider, and it still takes up space and moves the expansion tile a tiny bit when expanding.
ahahaha this is better than the check one
9

Be aware that while the solution

ExpansionTile(
  // ...
  shape: Border(),
)

succeeds in removing the borders, it leads to the title widget (and icons) to wiggle/slightly move upwards on expanding. This is because the layout is designed with the expectation that a border with minimal height is added in the expanded stage above the title widget (which we remove with the approach above). This does not happen in the other solution:

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

Comments

6

@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.

Comments

5

Using only shape is not enough to prevent the title from moving, both shape and collapsedShape must be provided.

ExpansionTile(
    shape: LinearBorder.none,
    collapsedShape: LinearBorder.none,
    ...

Comments

2

Don't override theme

the first solution is must be use own widget interface. Overriding theme is not a good solution at all. You must handle border settings through ExpansionTile interface.

ExpansionTile(
    shape: LinearBorder.none,
    ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.