-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is like an ExpansionTile but always displays the expanding arrow even when `trailing` is specified
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ExpansionTileWithArrow extends StatefulWidget { | ||
const ExpansionTileWithArrow( | ||
{super.key, | ||
required this.leading, | ||
required this.title, | ||
required this.subtitle, | ||
required this.trailing, | ||
required this.children}); | ||
|
||
final Widget leading; | ||
final Widget title; | ||
final Widget subtitle; | ||
final Widget trailing; | ||
final List<Widget> children; | ||
|
||
@override | ||
State<ExpansionTileWithArrow> createState() => _ExpansionTileWithArrowState(); | ||
} | ||
|
||
class _ExpansionTileWithArrowState extends State<ExpansionTileWithArrow> with SingleTickerProviderStateMixin { | ||
static final Animatable<double> _iconCurve = Tween<double>(begin: 0.0, end: 0.5).chain(CurveTween(curve: Curves.easeIn)); | ||
late Animation<double> _iconTurns; | ||
late AnimationController _animationController; | ||
|
||
@override | ||
void initState() { | ||
_animationController = AnimationController(duration: const Duration(milliseconds: 200), vsync: this); | ||
_iconTurns = _animationController.drive(_iconCurve); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExpansionTile( | ||
leading: widget.leading, | ||
title: widget.title, | ||
subtitle: widget.subtitle, | ||
trailing: FittedBox( | ||
child: Row( | ||
children: [ | ||
widget.trailing, | ||
RotationTransition( | ||
turns: _iconTurns, | ||
child: const Icon(Icons.expand_more), | ||
) | ||
], | ||
), | ||
), | ||
onExpansionChanged: (bool expanded) { | ||
setState(() { | ||
if (expanded) { | ||
_animationController.forward(); | ||
} else { | ||
_animationController.reverse(); | ||
} | ||
}); | ||
}, | ||
children: widget.children, | ||
); | ||
} | ||
} |