This project is a Flutter package that provides an container to the ExpansionTile
widget.
The ExpansionTileList
serves as a container for ExpansionTile
widgets. It provides an easy way to create a list of
items that can be expanded or collapsed to show or hide additional information.
- The
builder
property allows the customization of the creation of each tile in theExpansionTileList
. - The
tileGapSize
property allows you to specify the size of the gap between each tile in theExpansionTileList
. - Expand at most one Tile at a time.
- Extension of
ExpansionTile
class with acopyWith
method. - The
trailing
property allows you to specify the trailing widget for all tiles, can be overridden byExpansionTile
trailing property. - The
trailingAnimation
property allows you to specify the animation for the trailing widget.
To use this package, add expansion_tile_list
as
a dependency in your pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
expansion_tile_list: ^0.1.1
Import the package:
import 'package:expansion_tile_list/expansion_tile_list.dart';
Here's a simple example of how to use the ExpansionTileList
:
- Basic usage: This example shows how to create a list of
ExpansionTile
widgets using theExpansionTileList
widget.
import 'package:flutter/material.dart';
import 'package:expansion_tile_list/expansion_tile_list.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ExpansionTileList(
tileGapSize: 10.0,
children: <Widget>[
ExpansionTile(
title: Text('Tile 1'),
children: <Widget>[
Text('Child 1'),
],
),
ExpansionTile(
title: Text('Tile 2'),
children: <Widget>[
Text('Child 2'),
],
),
],
),
),
);
}
}
- Using
trailing
andtrailingAnimation
: This example shows how to use thetrailing
andtrailingAnimation
properties to customize the trailing widget of the tiles.
var expansionTileList =
ExpansionTileList(
trailing: Icon(Icons.arrow_drop_down),
trailingAnimation: Tween<double>(begin: 0, end: 0.5),
children: <ExpansionTile>[
ExpansionTile(
title: Text('Tile 1'),
children: <Widget>[Text('Child 1')],
),
ExpansionTile(
title: Text('Tile 2'),
children: <Widget>[Text('Child 2')],
),
],
);
- Using
trailingAnimationBuilder
: This property allows you to specify a custom animation for the trailing widget of the tiles.
var expansionTileList =
ExpansionTileList(
trailingAnimationBuilder: (context, index, value, child) {
return Transform.rotate(
angle: value * pi,
child: child,
);
},
children: <ExpansionTile>[
ExpansionTile(
title: Text('Tile 1'),
children: <Widget>[Text('Child 1')],
),
ExpansionTile(
title: Text('Tile 2'),
children: <Widget>[Text('Child 2')],
),
],
);
ExpansionTileList.radio
: This widget allows you to expand at most one tile at a time. TheinitialExpandedIndex
property allows you to specify the index of the tile that is initially expanded.
var expansionTileList =
ExpansionTileList.radio(
initialExpandedIndex: 0,
children: <ExpansionTile>[
ExpansionTile(
title: Text('Tile 1'),
children: <Widget>[Text('Child 1')],
),
ExpansionTile(
title: Text('Tile 2'),
children: <Widget>[Text('Child 2')],
),
],
);
Property | Description | Default Value |
---|---|---|
key |
The widget key. | null |
children |
The list of ExpansionTile widgets that are managed by this widget. | required |
onExpansionChanged |
Called whenever a tile is expanded or collapsed. | null |
tileGapSize |
The size of the gap between the tiles in the list. | 0.0 |
builder |
A builder that can be used to customize the appearance of the tiles. | null |
controller |
A controller that can be used to programmatically control the expansion of the tiles. | null |
trailing |
The widget that is displayed at the end of each tile header. Can be overridden by trailing property of ExpansionList |
null |
trailingAnimation |
The animation for the trailing widget of the tiles. No effect of trailing property of ExpansionList if specified |
null |
trailingAnimationEnabled |
Whether the trailing animation is enabled. If true, the trailing widget of the tiles is animated. | true |
trailingAnimationBuilder |
The builder for the trailing animation of the tiles. If null, the default animation is used. | null |
initialExpandedIndexes |
The indexes of the tiles that are initially expanded. | const <int>[] |
initialExpandedIndex |
The index of the tile that is initially expanded. If null, no tiles are initially expanded. | null |
This package includes thorough unit tests for the ExpansionTileExtension
. To run the tests, use the following command:
flutter test
Contributions are welcome! If you find a bug or want a feature, please fill an issue. If you want to contribute code, please submit a pull request. We welcome contributions from everyone. Before you start:
- Fork the repository to your own GitHub account.
- Clone the project to your machine.
- Create a branch locally with a descriptive name.
- Commit changes to the branch.
- Push changes to your fork.
- Create a new pull request in GitHub and link the issue you are fixing.
This project is licensed under the BSD-style license. See the LICENSE file for details.