play_btn.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. part of 'control_board.dart';
  2. class _PlayButton extends StatefulWidget {
  3. @override
  4. State<StatefulWidget> createState() => _PlayButtonState();
  5. }
  6. class _PlayButtonState extends State<_PlayButton> {
  7. final playerController = Get.find<IPlayerController>() as VidPlayerController;
  8. @override
  9. void initState() {
  10. WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  11. if (mounted) {
  12. playerController.eventHandler.addListener(onControllerEvent);
  13. }
  14. });
  15. super.initState();
  16. }
  17. @override
  18. void dispose() {
  19. playerController.eventHandler.removeListener(onControllerEvent);
  20. super.dispose();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. final playing = playerController.playing;
  25. const iconSize = 36.0;
  26. return IconButton(
  27. splashRadius: 2,
  28. padding: EdgeInsets.zero,
  29. onPressed: () {
  30. if (playing) {
  31. playerController.pause();
  32. // playerController.gotoFrame(playerController.currentFrameIndex);
  33. } else {
  34. playerController.play();
  35. }
  36. },
  37. icon: playing
  38. ? const Icon(
  39. Icons.pause_circle_outline,
  40. size: iconSize,
  41. color: Colors.white,
  42. )
  43. : const Icon(
  44. Icons.play_circle_outline,
  45. size: iconSize,
  46. color: Colors.white,
  47. ),
  48. );
  49. }
  50. void onControllerEvent(Object sender, VidPlayerEvent e) {
  51. if (e is VidPlayerStatusChangeEvent) {
  52. onPlayStatusChanged(e);
  53. }
  54. }
  55. void onPlayStatusChanged(VidPlayerStatusChangeEvent e) {
  56. if (mounted) {
  57. setState(() {});
  58. }
  59. }
  60. }