Repository: flutter
Issue: Flutter video_player widget doesn't fit into the parent widget.
Labels: platform-android,customer: solaris,p: video_player,package,has reproducible steps,P2,found in release: 2.2,team-android,triaged-android

Hello,
Greetings!.

I'm using a carouselslider widget under which I've added aspectratio widget followed by video_player widget. But, for some videos, video_player flows outside the carousel widget.

P.S.: Reference to issue no. #48854 

-----------------------------------------------------------------------------------
_**Please refer the screenshot for reference:-**_

<img src="https://user-images.githubusercontent.com/61319375/75089118-978a8f00-557b-11ea-92b0-d2358f5773b3.jpeg" height="500"/>

-----------------------------------------------------------------------------------
_**Flutter doctor:-**_

```
[✓] Flutter (Channel dev, v1.13.0, on Linux, locale en_GB.UTF-8)
    • Flutter version 1.13.0 at /home/neville/Projects/flutter
    • Framework revision 09126abb22 (3 months ago), 2019-12-03 17:43:00 -0800
    • Engine revision 6179380243
    • Dart version 2.7.0 (build 2.7.0-dev.2.1 a4d799c402)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/neville/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /home/neville/Projects/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Android Studio (version 3.5)
    • Android Studio at /home/neville/Projects/android-studio
    • Flutter plugin version 42.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.41.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.8.1

[✓] Connected device (1 available)
    • Mi A2 • f04cdaad • android-arm64 • Android 9 (API 28)

• No issues found!
```

--------------------------------------------------------------------------------------
_**Following is the code:-**_

<details>
<summary>sample code </summary>

```
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
import 'package:video_player/video_player.dart';

class VideoPlayerScreen extends StatefulWidget {
  final String videoUrl;

  VideoPlayerScreen({@required this.videoUrl, Key key}) : super(key: key);

  @override
  _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State {
  VideoPlayerController _controller;
  Future _initializeVideoPlayerFuture;
  bool _volumeUp = true;
  var _scaffoldKey = new GlobalKey();
  var a;

  @override
  void initState() {
// Create and store the VideoPlayerController. The VideoPlayerController
// offers several different constructors to play videos from assets, files,
// or the internet.
    _controller = VideoPlayerController.network(widget.videoUrl);

// Initialize the controller and store the Future for later use.
    _initializeVideoPlayerFuture = _controller.initialize();

    _controller.addListener(checkIfVideoFinished);

    super.initState();
  }

  void checkIfVideoFinished() {
    if (_controller.value.position == _controller.value.duration) {
      _controller.removeListener(checkIfVideoFinished);
      setState(() {
        _controller.pause();
      });
    }
  }

  @override
  void dispose() {
// Ensure disposing of the VideoPlayerController to free up resources.
    _controller.removeListener(checkIfVideoFinished);
    _controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return VisibilityDetector(
      key: _scaffoldKey,
      onVisibilityChanged: (VisibilityInfo info) {
        if (info.visibleFraction < 1.0) {
          if (_controller.value.isPlaying) {
            if (this.mounted) {
              setState(() {
                _controller.pause();
              });
            }
          }
        }
// debugPrint( widget.videoUrl + "\n ${info.visibleFraction} of my widget is visible");
      },
      child: Stack(
        children: [
          FutureBuilder(
            future: _initializeVideoPlayerFuture,
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.done) {
// If the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the video.
                return Align(
                  alignment: Alignment.center,
                  child: AspectRatio(
                    aspectRatio: 4 / 3,
                    child: VideoPlayer(_controller),
                  ),
                );
              } else {
// If the VideoPlayerController is still initializing, show a
// loading spinner.
                return Center(child: CircularProgressIndicator());
              }
            },
          ),
          Align(
            alignment: Alignment.bottomRight,
            child: Container(
              color: Colors.black87.withOpacity(0.3),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  IconButton(
                    icon: Icon(
                      _controller.value.isPlaying
                          ? Icons.pause
                          : Icons.play_arrow,
                    ),
                    color: Colors.white,
                    onPressed: () {
                      if (_controller.value.isPlaying) {
                        setState(() {
                          _controller.pause();
                        });
                        _controller.removeListener(checkIfVideoFinished);
                      } else {
                        setState(() {
                          _controller.play();
                        });
                        _controller.addListener(checkIfVideoFinished);
                      }
                    },
                  ),
                  IconButton(
                    icon: Icon(
                      _volumeUp ? Icons.volume_up : Icons.volume_off,
                    ),
                    color: Colors.white,
                    onPressed: () {
                      setState(() {
                        if (_volumeUp) {
                          _controller.setVolume(0.0);
                          _volumeUp = false;
                        } else {
                          _controller.setVolume(1.0);
                          _volumeUp = true;
                        }
                      });
                    },
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

```
</details>