Home > Blockchain >  A status bar is hidden when it comes back to portrait mode from landscape mode in the youtube player
A status bar is hidden when it comes back to portrait mode from landscape mode in the youtube player

Time:11-15

When you press the full-screen button of the youtube player it goes to landscape mode when you press it again it's come back to portrait mode but the status bar hides permanently throughout the app.

If anyone knows how to show the status bar persistent in Portrait mode. Please let me know. Thanks!

Here is the code:

import 'package:flutter/material.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';

/// Creates list of video players
class VideoList extends StatefulWidget {
  @override
  _VideoListState createState() => _VideoListState();
}

class _VideoListState extends State<VideoList> {
  final List<YoutubePlayerController> _controllers = [
    'K4TOrB7at0Y',
  ]
      .map<YoutubePlayerController>(
        (videoId) => YoutubePlayerController(
          initialVideoId: videoId,
          flags: const YoutubePlayerFlags(
            autoPlay: false,
          ),
        ),
      )
      .toList();

  @override
  Widget build(BuildContext context) {
    return YoutubePlayerBuilder(
      player: YoutubePlayer(controller: _controllers.first),
      builder: (p0, p1) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Video Player'),
          ),
          body: Column(children: [
            p1,
          ]),
        );
      },
    );
  }
}

Output: enter image description here Thanks!

CodePudding user response:

I think you should wrap Scaffold outside of YoutubePlayerBuider.

CodePudding user response:

Just add SystemUiOverlay.top inside onEnterFullScreen callback of YoutubePlayerBuilder, following way to show the status bar persistent.

onEnterFullScreen: () {
      SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
        SystemUiOverlay.top,
      ]);
}

Build Method

@override
  Widget build(BuildContext context) {
    return YoutubePlayerBuilder(
      onEnterFullScreen: () {
        SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
          SystemUiOverlay.top,
        ]);
      },
      player: YoutubePlayer(controller: _controllers.first),
      builder: (p0, p1) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Video Player'),
          ),
          body: Column(children: [
            p1,
          ]),
        );
      },
    );
  }
  • Related