newtaDev / pod_player

Video player for flutter web & mobile devices, Play video from youtube or vimeo or network in flutter using pod player
https://pub.dev/packages/pod_player
MIT License
106 stars 202 forks source link

enableFullScreen LateInitializationError #202

Open yce01 opened 6 months ago

yce01 commented 6 months ago

I initialized the controller

late final PodPlayerController fullVideoController;

@override void initState() { super.initState(); fullVideoController = PodPlayerController( playVideoFrom: PlayVideoFrom.youtube('https://youtu.be/$url', videoPlayerOptions: VideoPlayerOptions(allowBackgroundPlayback: true)), podPlayerConfig: const PodPlayerConfig( videoQualityPriority: [1080, 720, 360], autoPlay: true, isLooping: true, wakelockEnabled: true, )) ..initialise(); }

and then when I click a button, I want it to play in full screen.

ElevatedButton( onPressed: () { fullVideoController.enableFullScreen(); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xff00A6CC), visualDensity: VisualDensity.compact, padding: const EdgeInsets.symmetric(horizontal: 10), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), ), child: Text(tr('play_video'), style: const TextStyle(color: Colors.white)), ),

However, this is spitting out a LateInitializationError I/flutter (27513): ----------------FIREBASE CRASHLYTICS---------------- I/flutter (27513): LateInitializationError: Field 'mainContext' has not been initialized. I/flutter (27513): #0 _PodBaseController.mainContext (package:pod_player/src/controllers/pod_base_controller.dart) I/flutter (27513): #1 _PodVideoController._enableFullScreenView (package:pod_player/src/controllers/pod_video_controller.dart:230:9) I/flutter (27513): #2 _PodVideoController.enableFullScreen (package:pod_player/src/controllers/pod_video_controller.dart:179:7) I/flutter (27513): I/flutter (27513): ----------------------------------------------------

How can I solve this?