11import 'dart:math' ;
22import 'package:flutter/material.dart' ;
3+ import 'package:habr_app/widgets/link.dart' ;
34
45class Spoiler extends StatefulWidget {
56 final String ? title;
@@ -15,7 +16,7 @@ class _SpoilerState extends State<Spoiler> with TickerProviderStateMixin {
1516 late bool visible;
1617 late Animation _arrowAnimation;
1718 late AnimationController _arrowAnimationController;
18- static const duration = Duration (milliseconds: 300 );
19+ static const duration = Duration (milliseconds: 100 );
1920
2021 @override
2122 initState () {
@@ -27,6 +28,12 @@ class _SpoilerState extends State<Spoiler> with TickerProviderStateMixin {
2728 Tween (begin: 0.0 , end: pi / 2 ).animate (_arrowAnimationController);
2829 }
2930
31+ @override
32+ void dispose () {
33+ _arrowAnimationController.dispose ();
34+ super .dispose ();
35+ }
36+
3037 onTap () {
3138 setState (() {
3239 visible
@@ -50,14 +57,14 @@ class _SpoilerState extends State<Spoiler> with TickerProviderStateMixin {
5057 animation: _arrowAnimationController,
5158 builder: (context, child) => Transform .rotate (
5259 angle: _arrowAnimation.value, child: child),
53- child: Icon (Icons .arrow_right, color: themeData.primaryColor ),
60+ child: Icon (Icons .arrow_right, color: linkColorFrom (context) ),
5461 ),
5562 Expanded (
5663 child: Text (
5764 widget.title! ,
5865 style: TextStyle (
59- color: themeData.primaryColor ,
60- decorationColor: themeData.primaryColor ,
66+ color: linkColorFrom (context) ,
67+ decorationColor: linkColorFrom (context) ,
6168 decoration: TextDecoration .underline,
6269 decorationStyle: TextDecorationStyle .dashed,
6370 ),
@@ -66,12 +73,15 @@ class _SpoilerState extends State<Spoiler> with TickerProviderStateMixin {
6673 ),
6774 onTap: onTap,
6875 ),
69- if (visible) ...[
70- const SizedBox (
71- height: 10 ,
72- ),
73- widget.child! ,
74- ],
76+ SizeTransition (
77+ sizeFactor: Tween <double >(begin: 0 , end: 1 )
78+ .animate (_arrowAnimationController),
79+ axisAlignment: - 1.0 ,
80+ child: Column (children: [
81+ const SizedBox (height: 10 ),
82+ widget.child! ,
83+ ]),
84+ )
7585 ],
7686 ));
7787 }
0 commit comments