mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 02:37:25 +01:00
43 lines
1,004 B
Dart
43 lines
1,004 B
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
import '../backend.dart';
|
||
|
|
|
||
|
|
class PlayPauseButton extends StatefulWidget {
|
||
|
|
@override
|
||
|
|
_PlayPauseButtonState createState() => _PlayPauseButtonState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _PlayPauseButtonState extends State<PlayPauseButton>
|
||
|
|
with SingleTickerProviderStateMixin {
|
||
|
|
AnimationController playPauseAnimation;
|
||
|
|
Backend backend;
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
|
||
|
|
playPauseAnimation =
|
||
|
|
AnimationController(vsync: this, duration: Duration(milliseconds: 300));
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void didChangeDependencies() {
|
||
|
|
super.didChangeDependencies();
|
||
|
|
|
||
|
|
backend = Backend.of(context);
|
||
|
|
backend.playing.listen((playing) =>
|
||
|
|
playing ? playPauseAnimation.forward() : playPauseAnimation.reverse());
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return IconButton(
|
||
|
|
icon: AnimatedIcon(
|
||
|
|
icon: AnimatedIcons.play_pause,
|
||
|
|
progress: playPauseAnimation,
|
||
|
|
),
|
||
|
|
onPressed: backend.playPause,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|