Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video_player: add nullsafety support #2

Open
wants to merge 1 commit into
base: ricardo/develop2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"video_player","path":"/home/joe/Work/somus/plugins/packages/video_player/","dependencies":[]}],"android":[{"name":"video_player","path":"/home/joe/Work/somus/plugins/packages/video_player/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"video_player","dependencies":[]}],"date_created":"2021-05-30 18:50:55.437501","version":"2.0.6"}
30 changes: 5 additions & 25 deletions packages/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _VideoPlayPauseState extends State<VideoPlayPause> {

FadeAnimation imageFadeAnim =
FadeAnimation(child: const Icon(Icons.play_arrow, size: 100.0));
VoidCallback listener;
late VoidCallback listener;

VideoPlayerController get controller => widget.controller;

Expand Down Expand Up @@ -98,7 +98,7 @@ class FadeAnimation extends StatefulWidget {
FadeAnimation(
{this.child, this.duration = const Duration(milliseconds: 500)});

final Widget child;
final Widget? child;
final Duration duration;

@override
Expand All @@ -107,7 +107,7 @@ class FadeAnimation extends StatefulWidget {

class _FadeAnimationState extends State<FadeAnimation>
with SingleTickerProviderStateMixin {
AnimationController animationController;
late AnimationController animationController;

@override
void initState() {
Expand Down Expand Up @@ -184,7 +184,7 @@ class AssetPlayerLifeCycle extends PlayerLifeCycle {
}

abstract class _PlayerLifeCycleState extends State<PlayerLifeCycle> {
VideoPlayerController controller;
late VideoPlayerController controller;

@override

Expand Down Expand Up @@ -246,26 +246,6 @@ Widget buildCard(String title) {
leading: const Icon(Icons.airline_seat_flat_angled),
title: Text(title),
),
// TODO(jackson): Remove when deprecation is on stable branch
// ignore: deprecated_member_use
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('BUY TICKETS'),
onPressed: () {
/* ... */
},
),
FlatButton(
child: const Text('SELL TICKETS'),
onPressed: () {
/* ... */
},
),
],
),
),
],
),
);
Expand Down Expand Up @@ -328,7 +308,7 @@ class AspectRatioVideoState extends State<AspectRatioVideo> {
VideoPlayerController get controller => widget.controller;
bool initialized = false;

VoidCallback listener;
late VoidCallback listener;

@override
void initState() {
Expand Down
3 changes: 3 additions & 0 deletions packages/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ flutter:
assets:
- assets/flutter-mark-square-64.png
- assets/Butterfly-209.mp4

environment:
sdk: '>=2.12.0 <3.0.0'
104 changes: 54 additions & 50 deletions packages/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class VideoPlayerValue {
/// The total duration of the video.
///
/// Is null when [initialized] is false.
final Duration duration;
final Duration? duration;

/// The start position when clipped.
///
Expand Down Expand Up @@ -93,12 +93,12 @@ class VideoPlayerValue {
/// A description of the error if present.
///
/// If [hasError] is false this is [null].
final String errorDescription;
final String? errorDescription;

/// The [size] of the currently loaded video.
///
/// Is null when [initialized] is false.
final Size size;
final Size? size;

///The Current speed of the playback.
final double speed;
Expand All @@ -107,21 +107,21 @@ class VideoPlayerValue {

bool get hasError => errorDescription != null;

double get aspectRatio => size != null ? size.width / size.height : 1.0;
double get aspectRatio => size != null ? size!.width / size!.height : 1.0;

VideoPlayerValue copyWith({
Duration duration,
Size size,
Duration position,
Duration startPosition,
Duration endPosition,
List<DurationRange> buffered,
bool isPlaying,
bool isLooping,
bool isBuffering,
double volume,
String errorDescription,
double speed,
Duration? duration,
Size? size,
Duration? position,
Duration? startPosition,
Duration? endPosition,
List<DurationRange>? buffered,
bool? isPlaying,
bool? isLooping,
bool? isBuffering,
double? volume,
String? errorDescription,
double? speed,
}) {
return VideoPlayerValue(
duration: duration ?? this.duration,
Expand Down Expand Up @@ -214,20 +214,20 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
formatHint = null,
super(VideoPlayerValue(duration: null));

int _textureId;
final String dataSource;
final VideoFormat formatHint;
late int _textureId;
final String? dataSource;
final VideoFormat? formatHint;

/// Describes the type of data source this [VideoPlayerController]
/// is constructed with.
final DataSourceType dataSourceType;

final String package;
Timer _timer;
final String? package;
Timer? _timer;
bool _isDisposed = false;
Completer<void> _creatingCompleter;
StreamSubscription<dynamic> _eventSubscription;
_VideoAppLifeCycleObserver _lifeCycleObserver;
Completer<void>? _creatingCompleter;
StreamSubscription<dynamic>? _eventSubscription;
late _VideoAppLifeCycleObserver _lifeCycleObserver;

@visibleForTesting
int get textureId => _textureId;
Expand Down Expand Up @@ -256,13 +256,13 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
dataSourceDescription = <String, dynamic>{'uri': dataSource};
break;
}
final Map<String, dynamic> response =
final Map<String, dynamic>? response =
await _channel.invokeMapMethod<String, dynamic>(
'create',
dataSourceDescription,
);
_textureId = response['textureId'];
_creatingCompleter.complete(null);
_textureId = response!['textureId'];
_creatingCompleter!.complete(null);
final Completer<void> initializingCompleter = Completer<void>();

DurationRange toDurationRange(dynamic value) {
Expand Down Expand Up @@ -313,8 +313,9 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}

void errorListener(Object obj) {
final PlatformException e = obj;
value = VideoPlayerValue.erroneous(e.message);
// ignore: avoid_as
final PlatformException e = obj as PlatformException;
value = VideoPlayerValue.erroneous(e.message!);
_timer?.cancel();
}

Expand All @@ -331,7 +332,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
@override
Future<void> dispose() async {
if (_creatingCompleter != null) {
await _creatingCompleter.future;
await _creatingCompleter!.future;
if (!_isDisposed) {
_isDisposed = true;
_timer?.cancel();
Expand Down Expand Up @@ -387,7 +388,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
if (_isDisposed) {
return;
}
final Duration newPosition = await position;
final Duration? newPosition = await position;
if (_isDisposed) {
return;
}
Expand Down Expand Up @@ -417,15 +418,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}

/// The position in the current video.
Future<Duration> get position async {
Future<Duration?> get position async {
if (_isDisposed) {
return null;
}
return Duration(
milliseconds: await _channel.invokeMethod<int>(
milliseconds: (await _channel.invokeMethod<int>(
'position',
<String, dynamic>{'textureId': _textureId},
),
))!,
);
}

Expand Down Expand Up @@ -524,7 +525,7 @@ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {
final VideoPlayerController _controller;

void initialize() {
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance?.addObserver(this);
}

@override
Expand All @@ -544,7 +545,7 @@ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {
}

void dispose() {
WidgetsBinding.instance.removeObserver(this);
WidgetsBinding.instance?.removeObserver(this);
}
}

Expand All @@ -570,8 +571,8 @@ class _VideoPlayerState extends State<VideoPlayer> {
};
}

VoidCallback _listener;
int _textureId;
late VoidCallback _listener;
late int _textureId;

@override
void initState() {
Expand All @@ -585,7 +586,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
@override
void didUpdateWidget(VideoPlayer oldWidget) {
super.didUpdateWidget(oldWidget);
if (!oldWidget.controller._isDisposed) {
if (!oldWidget.controller.isDisposed) {
oldWidget.controller.removeListener(_listener);
}
_textureId = widget.controller.textureId;
Expand All @@ -595,7 +596,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
@override
void deactivate() {
super.deactivate();
if (!widget.controller._isDisposed) {
if (!widget.controller.isDisposed) {
widget.controller.removeListener(_listener);
}
}
Expand All @@ -620,8 +621,8 @@ class VideoProgressColors {

class _VideoScrubber extends StatefulWidget {
_VideoScrubber({
@required this.child,
@required this.controller,
required this.child,
required this.controller,
});

final Widget child;
Expand All @@ -639,10 +640,11 @@ class _VideoScrubberState extends State<_VideoScrubber> {
@override
Widget build(BuildContext context) {
void seekToRelativePosition(Offset globalPosition) {
final RenderBox box = context.findRenderObject();
final Offset tapPos = box.globalToLocal(globalPosition);
// ignore: avoid_as
final RenderBox? box = context.findRenderObject() as RenderBox;
final Offset tapPos = box!.globalToLocal(globalPosition);
final double relative = tapPos.dx / box.size.width;
final Duration position = controller.value.duration * relative;
final Duration position = controller.value.duration! * relative;
controller.seekTo(position);
}

Expand Down Expand Up @@ -689,14 +691,14 @@ class _VideoScrubberState extends State<_VideoScrubber> {
class VideoProgressIndicator extends StatefulWidget {
VideoProgressIndicator(
this.controller, {
VideoProgressColors colors,
VideoProgressColors? colors,
this.allowScrubbing,
this.padding = const EdgeInsets.only(top: 5.0),
}) : colors = colors ?? VideoProgressColors();

final VideoPlayerController controller;
final VideoProgressColors colors;
final bool allowScrubbing;
final bool? allowScrubbing;
final EdgeInsets padding;

@override
Expand All @@ -713,7 +715,7 @@ class _VideoProgressIndicatorState extends State<VideoProgressIndicator> {
};
}

VoidCallback listener;
late VoidCallback listener;

VideoPlayerController get controller => widget.controller;

Expand All @@ -735,7 +737,7 @@ class _VideoProgressIndicatorState extends State<VideoProgressIndicator> {
Widget build(BuildContext context) {
Widget progressIndicator;
if (controller.value.initialized) {
final int duration = controller.value.duration.inMilliseconds;
final int duration = controller.value.duration!.inMilliseconds;
final int position = controller.value.position.inMilliseconds;

int maxBuffering = 0;
Expand Down Expand Up @@ -772,7 +774,9 @@ class _VideoProgressIndicatorState extends State<VideoProgressIndicator> {
padding: widget.padding,
child: progressIndicator,
);
if (widget.allowScrubbing) {

final bool allowScrubbing = widget.allowScrubbing ?? false;
if (allowScrubbing) {
return _VideoScrubber(
child: paddedProgressIndicator,
controller: controller,
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player
description: Flutter plugin for displaying inline video with other Flutter
widgets on Android and iOS.
author: Flutter Team <[email protected]>
version: 0.11.0
version: 0.12.0
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player

flutter:
Expand All @@ -21,5 +21,5 @@ dev_dependencies:
sdk: flutter

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
sdk: ">=2.10.0 <3.0.0"
flutter: ">=2.0.0 <3.0.0"
Loading