Home > OS >  How to make ExpansionTile title clickable?
How to make ExpansionTile title clickable?

Time:04-19

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

CodePudding user response:

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

CodePudding user response:

Got the solution. It was pretty easy. Just wrap the text Widget into an Inkwell.

  • Related