Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Shorten API by adding getters
  • Loading branch information
cbenhagen committed Jan 16, 2019
commit 79abb082af1e910c46ad56a64c0f5a3607cea770
5 changes: 5 additions & 0 deletions lib/src/chewie_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class ChewieController extends ValueNotifier<ChewieValue> {
/// Defines if the controls should be for live stream video
final bool isLive;

bool get isFullScreen => value.isFullScreen;

VideoPlayerController get videoPlayerController =>
value.videoPlayerController;

Future _initialize() async {
await value.videoPlayerController.setLooping(looping);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ChewieState extends State<Chewie> {
}

void listener() async {
if (widget.controller.value.isFullScreen && !_isFullScreen) {
if (widget.controller.isFullScreen && !_isFullScreen) {
_isFullScreen = true;
await _pushFullScreenWidget(context);
} else if (_isFullScreen) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
final backgroundColor = widget.backgroundColor;
final iconColor = widget.iconColor;
chewieController = ChewieControllerProvider.of(context);
controller = chewieController.value.videoPlayerController;
controller = chewieController.videoPlayerController;
final orientation = MediaQuery.of(context).orientation;
final barHeight = orientation == Orientation.portrait ? 30.0 : 47.0;
final buttonPadding = orientation == Orientation.portrait ? 16.0 : 24.0;
Expand Down Expand Up @@ -73,7 +73,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
@override
void didChangeDependencies() {
chewieController = ChewieControllerProvider.of(context);
controller = chewieController.value.videoPlayerController;
controller = chewieController.videoPlayerController;

_dispose();
_initialize();
Expand Down Expand Up @@ -170,7 +170,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
),
child: Center(
child: Icon(
chewieController.value.isFullScreen
chewieController.isFullScreen
? OpenIconicIcons.fullscreenExit
: OpenIconicIcons.fullscreenEnter,
color: iconColor,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _MaterialControlsState extends State<MaterialControls> {
@override
void didChangeDependencies() {
chewieController = ChewieControllerProvider.of(context);
controller = chewieController.value.videoPlayerController;
controller = chewieController.videoPlayerController;

_dispose();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike initState, didChangeDependencies can run multiple times throughout the lifecycle of the Widget. Therefore, we may want to add some logic around this _dispose / initialize code: Only run that dispose and init IF the controller has changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it was also reinitializing when the theme changed. fc1bc16 fixes that.

_initialize();
Expand Down Expand Up @@ -115,7 +115,7 @@ class _MaterialControlsState extends State<MaterialControls> {
),
child: Center(
child: Icon(
chewieController.value.isFullScreen
chewieController.isFullScreen
? Icons.fullscreen_exit
: Icons.fullscreen,
),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class PlayerWithControls extends StatelessWidget {
chewieController.placeholder ?? Container(),
Center(
child: Hero(
tag: chewieController.value.videoPlayerController,
tag: chewieController.videoPlayerController,
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
_calculateAspectRatio(context),
child:
VideoPlayer(chewieController.value.videoPlayerController),
VideoPlayer(chewieController.videoPlayerController),
),
),
),
Expand Down