Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you change the height of an ExpansionTile in Flutter?

Tags:

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?

like image 862
Mary Avatar asked Sep 26 '17 17:09

Mary


People also ask

How do you increase ListTile height in flutter?

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.

How do you use ExpansionTile in flutter?

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.

How do you remove ExpansionTile padding?

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.


2 Answers

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.

like image 105
Collin Jackson Avatar answered Oct 11 '22 17:10

Collin Jackson


You might want to try this package : configurable_expansion_tile

enter image description here

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

like image 38
Rami Ibrahim Avatar answered Oct 11 '22 17:10

Rami Ibrahim