-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatedicon.dart
52 lines (47 loc) · 1.27 KB
/
animatedicon.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'package:flutter/material.dart';
class AnimatedIconWidget extends StatefulWidget {
const AnimatedIconWidget({super.key});
@override
State<AnimatedIconWidget> createState() => _AnimatedIconWidgetState();
}
class _AnimatedIconWidgetState extends State<AnimatedIconWidget>
with TickerProviderStateMixin {
bool _isPlaying = false;
late AnimationController _controller;
@override
void initState() {
_controller =
AnimationController(vsync: this, duration: const Duration(seconds: 1));
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Widget Name"),
),
body: Center(
child: GestureDetector(
onTap: (() {
if (_isPlaying == false) {
_controller.forward();
_isPlaying = true;
} else {
_controller.reverse();
_isPlaying = false;
}
}),
child: AnimatedIcon(
icon: AnimatedIcons.play_pause,
progress: _controller,
size: 100,
),
),
));
}
}