Skip to content

Commit

Permalink
Add ExpansionTileWithArrow class
Browse files Browse the repository at this point in the history
This is like an ExpansionTile but always displays the expanding arrow even when `trailing` is specified
  • Loading branch information
Restioson committed Aug 2, 2023
1 parent e9dfc4a commit 66d7a60
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions mobile/lib/common/expansion_tile_with_arrow.dart
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,
);
}
}

0 comments on commit 66d7a60

Please sign in to comment.