Muntasir Zaman
Muntasir Zaman

Reputation: 31

How to make ExpansionTile title clickable?

I mean, I want to go to another view when the title is tapped and expand/collapse when the icon in ExpansionTile is tapped.

here's my code:

ExpansionTile(
                  title: categories.isEmpty
                      ? Text('no items')
                      : Text(categories[i].name),
                  children: getSubCategories(i),
                );

Upvotes: 0

Views: 2337

Answers (2)

Muntasir Zaman
Muntasir Zaman

Reputation: 31

Got the solution. Just wrap the text Widget into an Inkwell.

Upvotes: 0

Viktor Kerkez
Viktor Kerkez

Reputation: 46596

ExpansionTile expands by design, if you want the children to be tappable either choose a widget that has onTap or wrap it with GestureDetector.

ExpansionTile(title: Text('Expansion tile'), children: [
  ListTile(
    leading: const Text('List tile'),
    onTap: () => Navigator.of(context).push(
      MaterialPageRoute(
        builder: (BuildContext context) {
          return Container();
        },
      ),
    ),
  ),
  GestureDetector(
    child: const Text('Wrapped'),
    onTap: () => Navigator.of(context).push(
      MaterialPageRoute(
        builder: (BuildContext context) {
          return Container();
        },
      ),
    ),
  )
])

Upvotes: 1

Related Questions