The ExpansionTile inherits from the ListTile, which has a fixed height. There are no input args for tile height.
I've tried wrapping the ExpansionTile in a Container widget with a hardcoded height, but that causes the children widgets to only take up the space within the hardcoded height. Currently, because the contents in the title
widget are large, I have a "Column overflowed by 23 pixels" message.
Is there any way to change an Expansion Tile's height? Or is there another Widget I could use that has the expansion/accordion feature?
Ok so the answer to this is that it isn't possible. A ListTile is a very, very basic built-in widget that can only be a particular height, and there is nothing you can do about it. If you want to do anything visually cool, with pictures etc like I have shown in my question, you have to create a custom CARD instead.
Code Implementation :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.
ListTileTheme( contentPadding: EdgeInsets. all(0), dense: true //removes additional space vertically child: ExpansionTile(...)) If the trailing space needs to be removed, you can use the modified Expansiontile widget as mentioned in https://stackoverflow.com/a/64162389/12661107 . Save this answer.
I would probably copy ExpansionTile
and make your own version. Sizing ListTile
is easy with a Container
or SizedBox
, but ExpansionTile
is a material widget and it doesn't look like it was built with your use case in mind.
You might want to try this package : configurable_expansion_tile
Example app :
import 'package:flutter/material.dart';
import 'package:configurable_expansion_tile/configurable_expansion_tile.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Configurable Expansion Tile Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Configurable Expansion Tile Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ConfigurableExpansionTile(
borderColorStart: Colors.blue,
borderColorEnd: Colors.orange,
animatedWidgetFollowingHeader: const Icon(
Icons.expand_more,
color: const Color(0xFF707070),
),
headerExpanded:
Flexible(child: Center(child: Text("A Header Changed"))),
header: Container(
color: Colors.transparent,
child: Center(child: Text("A Header"))),
headerBackgroundColorStart: Colors.grey,
expandedBackgroundColor: Colors.amber,
headerBackgroundColorEnd: Colors.teal,
children: [
Row(
children: <Widget>[Text("CHILD 1")],
),
Row(
children: <Widget>[Text("CHILD 2")],
)
],
)
],
),
),
);
}
}
It should get you the results you wanted.
Hope it helps,
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With