How do I remove space between leading Icon (default up/down arrow) and title in expansionTile in flutter

56 Views Asked by At

I am want to remove the space between in default leading icon and title in the expansion in flutter Image from reference: Image

I saw a answer on this question: Flutter expansionTile title padding but the answer doesn't work: tilePadding: EdgeInsets.zero,

Note: I want the icon and title as a single unit and comes under flex: 5

My Code:

ExpansionTile(
  controlAffinity: ListTileControlAffinity.leading,
  initiallyExpanded: false,
  tilePadding: EdgeInsets.zero,
  title: Row(
    children: [
      Expanded(
        flex: 5,
        child: Text(
          controller.reportData[index]['customer'],
          textAlign: TextAlign.left,
          overflow: TextOverflow.ellipsis,
          style: context.bodyLarge.copyWith(
            fontWeight: FontWeight.normal,
          ),
        ),
      ),
      .....
    ],
  ),
),
1

There are 1 best solutions below

1
On

Set a listTileTheme in your MaterialApp configuration with horizontalTitleGap to 0.0.

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test',
      theme: ThemeData(
        listTileTheme: const ListTileThemeData(horizontalTitleGap: 0.0),
      ),
      home: const MyHomePage(title: 'Test'),
    );
  }
}

Or just wrap your widgets inside a ListTileTheme widget with horizontalTitleGap to 0.0.

ListTileTheme(
  horizontalTitleGap: 0.0,
  child: Column(
    children: [
      ExpansionTile(
        controlAffinity: ListTileControlAffinity.leading,
        initiallyExpanded: false,
        tilePadding: EdgeInsets.zero,
        title: Row(
          children: [
            Expanded(
              flex: 5,
              child: Text(
                'example text',
                textAlign: TextAlign.left,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ],
        ),
      ),
    ],
  ),
),