Youtube_player_flutter: DeviceOrientation.portraitUp after fullscreen

Created on 12 May 2020  路  5Comments  路  Source: sarbagyastha/youtube_player_flutter

My app should be viewed in DeviceOrientation.portraitUp only. When I go full screen mode using youtube_player_flutter it of course goes full screen using landscape device orientation which is fine. However, when I close the fullscreen mode, landscape device orientation stays available, possibly messing up my app.

As a quick fix I changed the

if (controller.value.isFullScreen) {
        Navigator.pop(context);
      } 

to

if (controller.value.isFullScreen) {
        SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
            .then((_) {
          Navigator.pop(context);
        });
      } 

In your code. It would be nice if I could fix this using your controller without having to mess with your code.

Thanks,

Merijn

enhancement

All 5 comments

this PR allows to do that #226

I tried calling onExitFullScreen(), did nothing for me :

YoutubePlayerBuilder(
        onExitFullScreen: (){
          print('onExitFullScreen called!!');
          SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
        },
        player: YoutubePlayer(
          controller: _controller,
        ), builder: (context , player ) {
        return Column(
          children: <Widget>[
            player,
          ],
        );
      },
),

Instead, I got this in logs :

E/flutter (24017): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'call' was called on null.
E/flutter (24017): Receiver: null
E/flutter (24017): Tried calling: call()
E/flutter (24017): #0      _YoutubePlayerBuilderState.didChangeMetrics (package:youtube_player_flutter/src/widgets/youtube_player_builder.dart:60)
E/flutter (24017): #1      WidgetsBinding.handleMetricsChanged (package:flutter/src/widgets/binding.dart:538)
E/flutter (24017): #2      _rootRun (dart:async/zone.dart:1184)
E/flutter (24017): #3      _CustomZone.run (dart:async/zone.dart:1077)
E/flutter (24017): #4      _CustomZone.runGuarded (dart:async/zone.dart:979)
E/flutter (24017): #5      _invoke (dart:ui/hooks.dart:261)
E/flutter (24017): #6      _updateWindowMetrics (dart:ui/hooks.dart:64)

@vipinnegi90 Fix is on the way.

@vipinnegi90 Try with v7.0.0+3

@sarbagyastha It's working. Great!

Was this page helpful?
0 / 5 - 0 ratings