From 66d7a601385a625a4bdd392b4bbe474a8b87b50a Mon Sep 17 00:00:00 2001 From: Restioson Date: Wed, 2 Aug 2023 15:31:12 +0200 Subject: [PATCH] Add ExpansionTileWithArrow class This is like an ExpansionTile but always displays the expanding arrow even when `trailing` is specified --- .../lib/common/expansion_tile_with_arrow.dart | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 mobile/lib/common/expansion_tile_with_arrow.dart diff --git a/mobile/lib/common/expansion_tile_with_arrow.dart b/mobile/lib/common/expansion_tile_with_arrow.dart new file mode 100644 index 000000000..3ad6f7178 --- /dev/null +++ b/mobile/lib/common/expansion_tile_with_arrow.dart @@ -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 children; + + @override + State createState() => _ExpansionTileWithArrowState(); +} + +class _ExpansionTileWithArrowState extends State with SingleTickerProviderStateMixin { + static final Animatable _iconCurve = Tween(begin: 0.0, end: 0.5).chain(CurveTween(curve: Curves.easeIn)); + late Animation _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, + ); + } +}