12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- part of 'control_board.dart';
- class _PlayButton extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => _PlayButtonState();
- }
- class _PlayButtonState extends State<_PlayButton> {
- final playerController = Get.find<IPlayerController>() as VidPlayerController;
- @override
- void initState() {
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- if (mounted) {
- playerController.eventHandler.addListener(onControllerEvent);
- }
- });
- super.initState();
- }
- @override
- void dispose() {
- playerController.eventHandler.removeListener(onControllerEvent);
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final playing = playerController.playing;
- const iconSize = 36.0;
- return IconButton(
- splashRadius: 2,
- padding: EdgeInsets.zero,
- onPressed: () {
- if (playing) {
- playerController.pause();
- // playerController.gotoFrame(playerController.currentFrameIndex);
- } else {
- playerController.play();
- }
- },
- icon: playing
- ? const Icon(
- Icons.pause_circle_outline,
- size: iconSize,
- color: Colors.white,
- )
- : const Icon(
- Icons.play_circle_outline,
- size: iconSize,
- color: Colors.white,
- ),
- );
- }
- void onControllerEvent(Object sender, VidPlayerEvent e) {
- if (e is VidPlayerStatusChangeEvent) {
- onPlayStatusChanged(e);
- }
- }
- void onPlayStatusChanged(VidPlayerStatusChangeEvent e) {
- if (mounted) {
- setState(() {});
- }
- }
- }
|