[video_player] Switch platform interface to new analysis options (#4785)
diff --git a/packages/video_player/video_player_platform_interface/CHANGELOG.md b/packages/video_player/video_player_platform_interface/CHANGELOG.md
index 8d295aa..353f273 100644
--- a/packages/video_player/video_player_platform_interface/CHANGELOG.md
+++ b/packages/video_player/video_player_platform_interface/CHANGELOG.md
@@ -1,6 +1,7 @@
-## NEXT
+## 5.0.2
* Adds the Pigeon definitions used to create the method channel implementation.
+* Internal code cleanup for stricter analysis options.
## 5.0.1
diff --git a/packages/video_player/video_player_platform_interface/analysis_options.yaml b/packages/video_player/video_player_platform_interface/analysis_options.yaml
deleted file mode 100644
index 5aeb4e7..0000000
--- a/packages/video_player/video_player_platform_interface/analysis_options.yaml
+++ /dev/null
@@ -1 +0,0 @@
-include: ../../../analysis_options_legacy.yaml
diff --git a/packages/video_player/video_player_platform_interface/lib/messages.dart b/packages/video_player/video_player_platform_interface/lib/messages.dart
index 0ddbfae..831f4e3 100644
--- a/packages/video_player/video_player_platform_interface/lib/messages.dart
+++ b/packages/video_player/video_player_platform_interface/lib/messages.dart
@@ -4,7 +4,7 @@
// Autogenerated from Pigeon (v0.1.21), do not edit directly.
// See also: https://pub.dev/packages/pigeon
-// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import
+// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, cast_nullable_to_non_nullable
// @dart = 2.12
import 'dart:async';
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;
diff --git a/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart b/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart
index 31d1839..2aa7fb3 100644
--- a/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart
+++ b/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart
@@ -17,7 +17,7 @@
/// third-party implementations. It is not used by other implementations in
/// this repository.
class MethodChannelVideoPlayer extends VideoPlayerPlatform {
- VideoPlayerApi _api = VideoPlayerApi();
+ final VideoPlayerApi _api = VideoPlayerApi();
@override
Future<void> init() {
@@ -31,7 +31,7 @@
@override
Future<int?> create(DataSource dataSource) async {
- CreateMessage message = CreateMessage();
+ final CreateMessage message = CreateMessage();
switch (dataSource.sourceType) {
case DataSourceType.asset:
@@ -51,7 +51,7 @@
break;
}
- TextureMessage response = await _api.create(message);
+ final TextureMessage response = await _api.create(message);
return response.textureId;
}
@@ -97,7 +97,7 @@
@override
Future<Duration> getPosition(int textureId) async {
- PositionMessage response =
+ final PositionMessage response =
await _api.position(TextureMessage()..textureId = textureId);
return Duration(milliseconds: response.position!);
}
@@ -107,21 +107,21 @@
return _eventChannelFor(textureId)
.receiveBroadcastStream()
.map((dynamic event) {
- final Map<dynamic, dynamic> map = event;
+ final Map<dynamic, dynamic> map = event as Map<dynamic, dynamic>;
switch (map['event']) {
case 'initialized':
return VideoEvent(
eventType: VideoEventType.initialized,
- duration: Duration(milliseconds: map['duration']),
- size: Size(map['width']?.toDouble() ?? 0.0,
- map['height']?.toDouble() ?? 0.0),
+ duration: Duration(milliseconds: map['duration']! as int),
+ size: Size((map['width'] as num?)?.toDouble() ?? 0.0,
+ (map['height'] as num?)?.toDouble() ?? 0.0),
);
case 'completed':
return VideoEvent(
eventType: VideoEventType.completed,
);
case 'bufferingUpdate':
- final List<dynamic> values = map['values'];
+ final List<dynamic> values = map['values']! as List<dynamic>;
return VideoEvent(
buffered: values.map<DurationRange>(_toDurationRange).toList(),
@@ -162,10 +162,10 @@
};
DurationRange _toDurationRange(dynamic value) {
- final List<dynamic> pair = value;
+ final List<dynamic> pair = value as List<dynamic>;
return DurationRange(
- Duration(milliseconds: pair[0]),
- Duration(milliseconds: pair[1]),
+ Duration(milliseconds: pair[0]! as int),
+ Duration(milliseconds: pair[1]! as int),
);
}
}
diff --git a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart
index 451537a..f10fe66 100644
--- a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart
+++ b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart
@@ -127,7 +127,7 @@
this.formatHint,
this.asset,
this.package,
- this.httpHeaders = const {},
+ this.httpHeaders = const <String, String>{},
});
/// The way in which the video was originally loaded.
@@ -193,6 +193,7 @@
}
/// Event emitted from the platform implementation.
+@immutable
class VideoEvent {
/// Creates an instance of [VideoEvent].
///
@@ -200,6 +201,10 @@
///
/// Depending on the [eventType], the [duration], [size] and [buffered]
/// arguments can be null.
+ // TODO(stuartmorgan): Temporarily suppress warnings about not using const
+ // in all of the other video player packages, fix this, and then update
+ // the other packages to use const.
+ // ignore: prefer_const_constructors_in_immutables
VideoEvent({
required this.eventType,
this.duration,
@@ -270,9 +275,14 @@
/// Describes a discrete segment of time within a video using a [start] and
/// [end] [Duration].
+@immutable
class DurationRange {
/// Trusts that the given [start] and [end] are actually in order. They should
/// both be non-null.
+ // TODO(stuartmorgan): Temporarily suppress warnings about not using const
+ // in all of the other video player packages, fix this, and then update
+ // the other packages to use const.
+ // ignore: prefer_const_constructors_in_immutables
DurationRange(this.start, this.end);
/// The beginning of the segment described relative to the beginning of the
@@ -313,7 +323,8 @@
}
@override
- String toString() => '$runtimeType(start: $start, end: $end)';
+ String toString() =>
+ '${objectRuntimeType(this, 'DurationRange')}(start: $start, end: $end)';
@override
bool operator ==(Object other) =>
@@ -328,14 +339,19 @@
}
/// [VideoPlayerOptions] can be optionally used to set additional player settings
+@immutable
class VideoPlayerOptions {
+ /// set additional optional player settings
+ // TODO(stuartmorgan): Temporarily suppress warnings about not using const
+ // in all of the other video player packages, fix this, and then update
+ // the other packages to use const.
+ // ignore: prefer_const_constructors_in_immutables
+ VideoPlayerOptions({this.mixWithOthers = false});
+
/// Set this to true to mix the video players audio with other audio sources.
/// The default value is false
///
/// Note: This option will be silently ignored in the web platform (there is
/// currently no way to implement this feature in this platform).
final bool mixWithOthers;
-
- /// set additional optional player settings
- VideoPlayerOptions({this.mixWithOthers = false});
}
diff --git a/packages/video_player/video_player_platform_interface/pubspec.yaml b/packages/video_player/video_player_platform_interface/pubspec.yaml
index b7d5745..7d5bd83 100644
--- a/packages/video_player/video_player_platform_interface/pubspec.yaml
+++ b/packages/video_player/video_player_platform_interface/pubspec.yaml
@@ -4,7 +4,7 @@
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 5.0.1
+version: 5.0.2
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart b/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart
index 4d1c9b7..75baba4 100644
--- a/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart
+++ b/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart
@@ -13,7 +13,7 @@
import 'test.dart';
class _ApiLogger implements TestHostVideoPlayerApi {
- final List<String> log = [];
+ final List<String> log = <String>[];
TextureMessage? textureMessage;
CreateMessage? createMessage;
PositionMessage? positionMessage;
@@ -148,7 +148,7 @@
expect(log.createMessage?.uri, 'someUri');
expect(log.createMessage?.packageName, null);
expect(log.createMessage?.formatHint, 'dash');
- expect(log.createMessage?.httpHeaders, {});
+ expect(log.createMessage?.httpHeaders, <Object?, Object?>{});
expect(textureId, 3);
});
@@ -156,14 +156,15 @@
final int? textureId = await player.create(DataSource(
sourceType: DataSourceType.network,
uri: 'someUri',
- httpHeaders: {'Authorization': 'Bearer token'},
+ httpHeaders: <String, String>{'Authorization': 'Bearer token'},
));
expect(log.log.last, 'create');
expect(log.createMessage?.asset, null);
expect(log.createMessage?.uri, 'someUri');
expect(log.createMessage?.packageName, null);
expect(log.createMessage?.formatHint, null);
- expect(log.createMessage?.httpHeaders, {'Authorization': 'Bearer token'});
+ expect(log.createMessage?.httpHeaders,
+ <String, String>{'Authorization': 'Bearer token'});
expect(textureId, 3);
});
@@ -238,7 +239,7 @@
_ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.setMockMessageHandler(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
(ByteData? message) async {
final MethodCall methodCall =
const StandardMethodCodec().decodeMethodCall(message);
@@ -246,7 +247,7 @@
await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'initialized',
@@ -259,7 +260,7 @@
await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'completed',
@@ -269,7 +270,7 @@
await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'bufferingUpdate',
@@ -283,7 +284,7 @@
await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'bufferingStart',
@@ -293,7 +294,7 @@
await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
- "flutter.io/videoPlayer/videoEvents123",
+ 'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'bufferingEnd',
diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml
index 7ef7969..0dbeae4 100644
--- a/script/configs/custom_analysis.yaml
+++ b/script/configs/custom_analysis.yaml
@@ -26,5 +26,4 @@
- in_app_purchase/in_app_purchase_android
- in_app_purchase/in_app_purchase_storekit
- video_player/video_player
-- video_player/video_player_platform_interface
- video_player/video_player_web