Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 683
Paul Coshott Avatar asked Jul 01 '20 00:07

Paul Coshott


People also ask

How do you remove icons from ExpansionTile flutter?

If you are using ExpantionTile inside the panel, you can provide trailing widget to it which will replace the arrow. Show activity on this post. I had a similar issue with ExpandablePanel, I created an ExpandableThemeData and set the hasIcon property to false.

How do you expand a ListTile in flutter?

You need to implement it in your code respectively: Create a new dart file called expansion_title_demo. dart inside the lib folder. In this screen, we will create a list with the help of a list view builder in which the expansion tile widget will be used and initialize the list data into the expansion tile widget.

How expanded works flutter?

Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space along the main axis (e.g., horizontally for a Row or vertically for a Column). If multiple children are expanded, the available space is divided among them according to the flex factor.


2 Answers

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

like image 119
Dasunx Avatar answered Oct 13 '22 21:10

Dasunx


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

like image 1
pierrepierre Avatar answered Oct 13 '22 19:10

pierrepierre