[video_player] Update app-facing package analysis options (#4786)
diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index adf696a..ee0accb 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md
@@ -1,3 +1,7 @@ +## 2.2.19 + +* Internal code cleanup for stricter analysis options. + ## 2.2.18 * Moves Android and iOS implementations to federated packages.
diff --git a/packages/video_player/video_player/analysis_options.yaml b/packages/video_player/video_player/analysis_options.yaml deleted file mode 100644 index 5aeb4e7..0000000 --- a/packages/video_player/video_player/analysis_options.yaml +++ /dev/null
@@ -1 +0,0 @@ -include: ../../../analysis_options_legacy.yaml
diff --git a/packages/video_player/video_player/example/integration_test/controller_swap_test.dart b/packages/video_player/video_player/example/integration_test/controller_swap_test.dart index 8478076..f80e600 100644 --- a/packages/video_player/video_player/example/integration_test/controller_swap_test.dart +++ b/packages/video_player/video_player/example/integration_test/controller_swap_test.dart
@@ -6,8 +6,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:integration_test/integration_test.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; import 'package:video_player/video_player.dart'; const Duration _playDuration = Duration(seconds: 1); @@ -18,13 +18,13 @@ 'can substitute one controller by another without crashing', (WidgetTester tester) async { // Use WebM for web to allow CI to use Chromium. - final String videoAssetKey = + const String videoAssetKey = kIsWeb ? 'assets/Butterfly-209.webm' : 'assets/Butterfly-209.mp4'; - VideoPlayerController controller = VideoPlayerController.asset( + final VideoPlayerController controller = VideoPlayerController.asset( videoAssetKey, ); - VideoPlayerController another = VideoPlayerController.asset( + final VideoPlayerController another = VideoPlayerController.asset( videoAssetKey, ); await controller.initialize(); @@ -32,18 +32,16 @@ await controller.setVolume(0); await another.setVolume(0); - final Completer<void> started = Completer(); - final Completer<void> ended = Completer(); - bool startedBuffering = false; - bool endedBuffering = false; + final Completer<void> started = Completer<void>(); + final Completer<void> ended = Completer<void>(); another.addListener(() { - if (another.value.isBuffering && !startedBuffering) { - startedBuffering = true; + if (another.value.isBuffering && !started.isCompleted) { started.complete(); } - if (startedBuffering && !another.value.isBuffering && !endedBuffering) { - endedBuffering = true; + if (started.isCompleted && + !another.value.isBuffering && + !ended.isCompleted) { ended.complete(); } }); @@ -69,11 +67,8 @@ expect(another.value.position, (Duration position) => position > const Duration(seconds: 0)); - await started; - expect(startedBuffering, true); - - await ended; - expect(endedBuffering, true); + await expectLater(started.future, completes); + await expectLater(ended.future, completes); }, skip: !(kIsWeb || defaultTargetPlatform == TargetPlatform.android), ); @@ -86,7 +81,7 @@ textDirection: TextDirection.ltr, child: Center( child: AspectRatio( - key: Key('same'), + key: const Key('same'), aspectRatio: controller.value.aspectRatio, child: VideoPlayer(controller), ),
diff --git a/packages/video_player/video_player/example/integration_test/video_player_test.dart b/packages/video_player/video_player/example/integration_test/video_player_test.dart index 0c2252b..746c63f 100644 --- a/packages/video_player/video_player/example/integration_test/video_player_test.dart +++ b/packages/video_player/video_player/example/integration_test/video_player_test.dart
@@ -17,7 +17,7 @@ const Duration _playDuration = Duration(seconds: 1); // Use WebM for web to allow CI to use Chromium. -final String _videoAssetKey = +const String _videoAssetKey = kIsWeb ? 'assets/Butterfly-209.webm' : 'assets/Butterfly-209.mp4'; // Returns the URL to load an asset from this example app as a network source. @@ -48,13 +48,14 @@ expect(_controller.value.isPlaying, false); // The WebM version has a slightly different duration than the MP4. expect(_controller.value.duration, - Duration(seconds: 7, milliseconds: kIsWeb ? 544 : 540)); + const Duration(seconds: 7, milliseconds: kIsWeb ? 544 : 540)); }); testWidgets( 'live stream duration != 0', (WidgetTester tester) async { - VideoPlayerController networkController = VideoPlayerController.network( + final VideoPlayerController networkController = + VideoPlayerController.network( 'https://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8', ); await networkController.initialize(); @@ -65,7 +66,7 @@ expect(networkController.value.duration, (Duration duration) => duration != Duration.zero); }, - skip: (kIsWeb), + skip: kIsWeb, ); testWidgets( @@ -124,7 +125,7 @@ // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes await _controller.setVolume(0); - Duration tenMillisBeforeEnd = + final Duration tenMillisBeforeEnd = _controller.value.duration - const Duration(milliseconds: 10); await _controller.seekTo(tenMillisBeforeEnd); await _controller.play(); @@ -203,12 +204,12 @@ group('file-based videos', () { setUp(() async { // Load the data from the asset. - String tempDir = (await getTemporaryDirectory()).path; - ByteData bytes = await rootBundle.load(_videoAssetKey); + final String tempDir = (await getTemporaryDirectory()).path; + final ByteData bytes = await rootBundle.load(_videoAssetKey); // Write it to a file to use as a source. final String filename = _videoAssetKey.split('/').last; - File file = File('$tempDir/$filename'); + final File file = File('$tempDir/$filename'); await file.writeAsBytes(bytes.buffer.asInt8List()); _controller = VideoPlayerController.file(file); @@ -244,8 +245,8 @@ // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes await _controller.setVolume(0); - final Completer<void> started = Completer(); - final Completer<void> ended = Completer(); + final Completer<void> started = Completer<void>(); + final Completer<void> ended = Completer<void>(); _controller.addListener(() { if (!started.isCompleted && _controller.value.isBuffering) { started.complete(); @@ -291,7 +292,7 @@ // The audio was made with 44100 Hz, 192 Kbps CBR, and 32 bits. expect( _controller.value.duration, - Duration(seconds: 5, milliseconds: kIsWeb ? 42 : 41), + const Duration(seconds: 5, milliseconds: kIsWeb ? 42 : 41), ); });
diff --git a/packages/video_player/video_player/example/lib/main.dart b/packages/video_player/video_player/example/lib/main.dart index 9297cc6..5d496a9 100644 --- a/packages/video_player/video_player/example/lib/main.dart +++ b/packages/video_player/video_player/example/lib/main.dart
@@ -47,10 +47,10 @@ tabs: <Widget>[ Tab( icon: Icon(Icons.cloud), - text: "Remote", + text: 'Remote', ), - Tab(icon: Icon(Icons.insert_drive_file), text: "Asset"), - Tab(icon: Icon(Icons.list), text: "List example"), + Tab(icon: Icon(Icons.insert_drive_file), text: 'Asset'), + Tab(icon: Icon(Icons.list), text: 'List example'), ], ), ), @@ -71,20 +71,20 @@ Widget build(BuildContext context) { return ListView( children: <Widget>[ - _ExampleCard(title: "Item a"), - _ExampleCard(title: "Item b"), - _ExampleCard(title: "Item c"), - _ExampleCard(title: "Item d"), - _ExampleCard(title: "Item e"), - _ExampleCard(title: "Item f"), - _ExampleCard(title: "Item g"), + const _ExampleCard(title: 'Item a'), + const _ExampleCard(title: 'Item b'), + const _ExampleCard(title: 'Item c'), + const _ExampleCard(title: 'Item d'), + const _ExampleCard(title: 'Item e'), + const _ExampleCard(title: 'Item f'), + const _ExampleCard(title: 'Item g'), Card( child: Column(children: <Widget>[ Column( children: <Widget>[ const ListTile( leading: Icon(Icons.cake), - title: Text("Video video"), + title: Text('Video video'), ), Stack( alignment: FractionalOffset.bottomRight + @@ -96,11 +96,11 @@ ], ), ])), - _ExampleCard(title: "Item h"), - _ExampleCard(title: "Item i"), - _ExampleCard(title: "Item j"), - _ExampleCard(title: "Item k"), - _ExampleCard(title: "Item l"), + const _ExampleCard(title: 'Item h'), + const _ExampleCard(title: 'Item i'), + const _ExampleCard(title: 'Item j'), + const _ExampleCard(title: 'Item k'), + const _ExampleCard(title: 'Item l'), ], ); } @@ -269,7 +269,7 @@ const _ControlsOverlay({Key? key, required this.controller}) : super(key: key); - static const _exampleCaptionOffsets = [ + static const List<Duration> _exampleCaptionOffsets = <Duration>[ Duration(seconds: -10), Duration(seconds: -3), Duration(seconds: -1, milliseconds: -500), @@ -280,7 +280,7 @@ Duration(seconds: 3), Duration(seconds: 10), ]; - static const _examplePlaybackRates = [ + static const List<double> _examplePlaybackRates = <double>[ 0.25, 0.5, 1.0, @@ -298,13 +298,13 @@ return Stack( children: <Widget>[ AnimatedSwitcher( - duration: Duration(milliseconds: 50), - reverseDuration: Duration(milliseconds: 200), + duration: const Duration(milliseconds: 50), + reverseDuration: const Duration(milliseconds: 200), child: controller.value.isPlaying - ? SizedBox.shrink() + ? const SizedBox.shrink() : Container( color: Colors.black26, - child: Center( + child: const Center( child: Icon( Icons.play_arrow, color: Colors.white, @@ -324,13 +324,13 @@ child: PopupMenuButton<Duration>( initialValue: controller.value.captionOffset, tooltip: 'Caption Offset', - onSelected: (delay) { + onSelected: (Duration delay) { controller.setCaptionOffset(delay); }, - itemBuilder: (context) { - return [ - for (final offsetDuration in _exampleCaptionOffsets) - PopupMenuItem( + itemBuilder: (BuildContext context) { + return <PopupMenuItem<Duration>>[ + for (final Duration offsetDuration in _exampleCaptionOffsets) + PopupMenuItem<Duration>( value: offsetDuration, child: Text('${offsetDuration.inMilliseconds}ms'), ) @@ -353,13 +353,13 @@ child: PopupMenuButton<double>( initialValue: controller.value.playbackSpeed, tooltip: 'Playback speed', - onSelected: (speed) { + onSelected: (double speed) { controller.setPlaybackSpeed(speed); }, - itemBuilder: (context) { - return [ - for (final speed in _examplePlaybackRates) - PopupMenuItem( + itemBuilder: (BuildContext context) { + return <PopupMenuItem<double>>[ + for (final double speed in _examplePlaybackRates) + PopupMenuItem<double>( value: speed, child: Text('${speed}x'), )
diff --git a/packages/video_player/video_player/example/pubspec.yaml b/packages/video_player/video_player/example/pubspec.yaml index eef6eb7..6032f3c 100644 --- a/packages/video_player/video_player/example/pubspec.yaml +++ b/packages/video_player/video_player/example/pubspec.yaml
@@ -18,14 +18,13 @@ path: ../ dev_dependencies: - flutter_test: - sdk: flutter flutter_driver: sdk: flutter + flutter_test: + sdk: flutter integration_test: sdk: flutter path_provider: ^2.0.6 - pedantic: ^1.10.0 test: any flutter:
diff --git a/packages/video_player/video_player/example/test_driver/video_player_test.dart b/packages/video_player/video_player/example/test_driver/video_player_test.dart index 1d5ac79..5fbed80 100644 --- a/packages/video_player/video_player/example/test_driver/video_player_test.dart +++ b/packages/video_player/video_player/example/test_driver/video_player_test.dart
@@ -12,8 +12,8 @@ await driver.close(); }); - //TODO(cyanglaz): Use TabBar tabs to navigate between pages after https://github.com/flutter/flutter/issues/16991 is fixed. - //TODO(cyanglaz): Un-skip the test after https://github.com/flutter/flutter/issues/43012 is fixed + // TODO(cyanglaz): Use TabBar tabs to navigate between pages after https://github.com/flutter/flutter/issues/16991 is fixed. + // TODO(cyanglaz): Un-skip the test after https://github.com/flutter/flutter/issues/43012 is fixed test('Push a page contains video and pop back, do not crash.', () async { final SerializableFinder pushTab = find.byValueKey('push_tab'); await driver.waitFor(pushTab);
diff --git a/packages/video_player/video_player/lib/src/closed_caption_file.dart b/packages/video_player/video_player/lib/src/closed_caption_file.dart index e410e26..324ffc4 100644 --- a/packages/video_player/video_player/lib/src/closed_caption_file.dart +++ b/packages/video_player/video_player/lib/src/closed_caption_file.dart
@@ -2,10 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'sub_rip.dart'; -export 'sub_rip.dart' show SubRipCaptionFile; +import 'package:flutter/foundation.dart' show objectRuntimeType; +import 'sub_rip.dart'; import 'web_vtt.dart'; + +export 'sub_rip.dart' show SubRipCaptionFile; export 'web_vtt.dart' show WebVTTCaptionFile; /// A structured representation of a parsed closed caption file. @@ -66,7 +68,7 @@ @override String toString() { - return '$runtimeType(' + return '${objectRuntimeType(this, 'Caption')}(' 'number: $number, ' 'start: $start, ' 'end: $end, '
diff --git a/packages/video_player/video_player/lib/src/sub_rip.dart b/packages/video_player/video_player/lib/src/sub_rip.dart index 5d6863f..7b807cd 100644 --- a/packages/video_player/video_player/lib/src/sub_rip.dart +++ b/packages/video_player/video_player/lib/src/sub_rip.dart
@@ -28,8 +28,10 @@ List<Caption> _parseCaptionsFromSubRipString(String file) { final List<Caption> captions = <Caption>[]; - for (List<String> captionLines in _readSubRipFile(file)) { - if (captionLines.length < 3) break; + for (final List<String> captionLines in _readSubRipFile(file)) { + if (captionLines.length < 3) { + break; + } final int captionNumber = int.parse(captionLines[0]); final _CaptionRange captionRange = @@ -52,11 +54,11 @@ } class _CaptionRange { + _CaptionRange(this.start, this.end); + final Duration start; final Duration end; - _CaptionRange(this.start, this.end); - // Assumes format from an SubRip file. // For example: // 00:01:54,724 --> 00:01:56,760
diff --git a/packages/video_player/video_player/lib/src/web_vtt.dart b/packages/video_player/video_player/lib/src/web_vtt.dart index 6c4527d..5527e62 100644 --- a/packages/video_player/video_player/lib/src/web_vtt.dart +++ b/packages/video_player/video_player/lib/src/web_vtt.dart
@@ -5,9 +5,9 @@ import 'dart:convert'; import 'package:html/dom.dart'; +import 'package:html/parser.dart' as html_parser; import 'closed_caption_file.dart'; -import 'package:html/parser.dart' as html_parser; /// Represents a [ClosedCaptionFile], parsed from the WebVTT file format. /// See: https://en.wikipedia.org/wiki/WebVTT @@ -28,10 +28,10 @@ final List<Caption> captions = <Caption>[]; // Ignore metadata - Set<String> metadata = {'HEADER', 'NOTE', 'REGION', 'WEBVTT'}; + final Set<String> metadata = <String>{'HEADER', 'NOTE', 'REGION', 'WEBVTT'}; int captionNumber = 1; - for (List<String> captionLines in _readWebVTTFile(file)) { + for (final List<String> captionLines in _readWebVTTFile(file)) { // CaptionLines represent a complete caption. // E.g // [ @@ -39,14 +39,18 @@ // ['Introduction'] // ] // If caption has just header or time, but no text, `captionLines.length` will be 1. - if (captionLines.length < 2) continue; + if (captionLines.length < 2) { + continue; + } // If caption has header equal metadata, ignore. - String metadaType = captionLines[0].split(' ')[0]; - if (metadata.contains(metadaType)) continue; + final String metadaType = captionLines[0].split(' ')[0]; + if (metadata.contains(metadaType)) { + continue; + } // Caption has header - bool hasHeader = captionLines.length > 2; + final bool hasHeader = captionLines.length > 2; if (hasHeader) { final int? tryParseCaptionNumber = int.tryParse(captionLines[0]); if (tryParseCaptionNumber != null) { @@ -82,11 +86,11 @@ } class _CaptionRange { + _CaptionRange(this.start, this.end); + final Duration start; final Duration end; - _CaptionRange(this.start, this.end); - // Assumes format from an VTT file. // For example: // 00:09.000 --> 00:11.000 @@ -161,7 +165,7 @@ return null; } - List<String> milisecondsStyles = dotSections[1].split(" "); + final List<String> milisecondsStyles = dotSections[1].split(' '); // TODO(cyanglaz): Handle caption styles. // https://github.com/flutter/flutter/issues/90009. @@ -172,7 +176,7 @@ // ``` // For a better readable code style, style parsing should happen before // calling this method. See: https://github.com/flutter/plugins/pull/2878/files#r713381134. - int milliseconds = int.parse(milisecondsStyles[0]); + final int milliseconds = int.parse(milisecondsStyles[0]); return Duration( hours: hours,
diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index 8fd2162..672ba2e 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart
@@ -10,16 +10,17 @@ import 'package:flutter/services.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; +import 'src/closed_caption_file.dart'; + export 'package:video_player_platform_interface/video_player_platform_interface.dart' show DurationRange, DataSourceType, VideoFormat, VideoPlayerOptions; -import 'src/closed_caption_file.dart'; export 'src/closed_caption_file.dart'; VideoPlayerPlatform? _lastVideoPlayerPlatform; VideoPlayerPlatform get _videoPlayerPlatform { - VideoPlayerPlatform currentInstance = VideoPlayerPlatform.instance; + final VideoPlayerPlatform currentInstance = VideoPlayerPlatform.instance; if (_lastVideoPlayerPlatform != currentInstance) { // This will clear all open videos on the platform when a full restart is // performed. @@ -32,10 +33,6 @@ /// The duration, current position, buffering state, error state and settings /// of a [VideoPlayerController]. class VideoPlayerValue { - /// This constant is just to indicate that parameter is not passed to [copyWith] - /// workaround for this issue https://github.com/dart-lang/language/issues/2009 - static const _defaultErrorDescription = 'defaultErrorDescription'; - /// Constructs a video with the given values. Only [duration] is required. The /// rest will initialize with default values when unset. VideoPlayerValue({ @@ -65,6 +62,10 @@ isInitialized: false, errorDescription: errorDescription); + /// This constant is just to indicate that parameter is not passed to [copyWith] + /// workaround for this issue https://github.com/dart-lang/language/issues/2009 + static const String _defaultErrorDescription = 'defaultErrorDescription'; + /// The total duration of the video. /// /// The duration is [Duration.zero] if the video hasn't been initialized. @@ -172,7 +173,7 @@ @override String toString() { - return '$runtimeType(' + return '${objectRuntimeType(this, 'VideoPlayerValue')}(' 'duration: $duration, ' 'size: $size, ' 'position: $position, ' @@ -209,7 +210,7 @@ {this.package, this.closedCaptionFile, this.videoPlayerOptions}) : dataSourceType = DataSourceType.asset, formatHint = null, - httpHeaders = const {}, + httpHeaders = const <String, String>{}, super(VideoPlayerValue(duration: Duration.zero)); /// Constructs a [VideoPlayerController] playing a video from obtained from @@ -226,7 +227,7 @@ this.formatHint, this.closedCaptionFile, this.videoPlayerOptions, - this.httpHeaders = const {}, + this.httpHeaders = const <String, String>{}, }) : dataSourceType = DataSourceType.network, package = null, super(VideoPlayerValue(duration: Duration.zero)); @@ -241,7 +242,7 @@ dataSourceType = DataSourceType.file, package = null, formatHint = null, - httpHeaders = const {}, + httpHeaders = const <String, String>{}, super(VideoPlayerValue(duration: Duration.zero)); /// Constructs a [VideoPlayerController] playing a video from a contentUri. @@ -256,7 +257,7 @@ dataSourceType = DataSourceType.contentUri, package = null, formatHint = null, - httpHeaders = const {}, + httpHeaders = const <String, String>{}, super(VideoPlayerValue(duration: Duration.zero)); /// The URI to the video file. This will be in different formats depending on @@ -393,9 +394,7 @@ } if (closedCaptionFile != null) { - if (_closedCaptionFile == null) { - _closedCaptionFile = await closedCaptionFile; - } + _closedCaptionFile ??= await closedCaptionFile; value = value.copyWith(caption: _getCaptionAt(value.position)); } @@ -513,7 +512,9 @@ // Setting the playback speed on iOS will trigger the video to play. We // prevent this from happening by not applying the playback speed until // the video is manually played from Flutter. - if (!value.isPlaying) return; + if (!value.isPlaying) { + return; + } await _videoPlayerPlatform.setPlaybackSpeed( _textureId, @@ -618,9 +619,9 @@ return Caption.none; } - final delayedPosition = position + value.captionOffset; - // TODO: This would be more efficient as a binary search. - for (final caption in _closedCaptionFile!.captions) { + final Duration delayedPosition = position + value.captionOffset; + // TODO(johnsonmh): This would be more efficient as a binary search. + for (final Caption caption in _closedCaptionFile!.captions) { if (caption.start <= delayedPosition && caption.end >= delayedPosition) { return caption; } @@ -682,7 +683,7 @@ /// Widget that displays the video controlled by [controller]. class VideoPlayer extends StatefulWidget { /// Uses the given [controller] for all video rendered in this widget. - VideoPlayer(this.controller); + const VideoPlayer(this.controller); /// The [VideoPlayerController] responsible for the video being rendered in /// this widget. @@ -780,7 +781,7 @@ } class _VideoScrubber extends StatefulWidget { - _VideoScrubber({ + const _VideoScrubber({ required this.child, required this.controller, }); @@ -800,7 +801,7 @@ @override Widget build(BuildContext context) { void seekToRelativePosition(Offset globalPosition) { - final RenderBox box = context.findRenderObject() as RenderBox; + 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; @@ -855,7 +856,7 @@ /// Defaults will be used for everything except [controller] if they're not /// provided. [allowScrubbing] defaults to false, and [padding] will default /// to `top: 5.0`. - VideoProgressIndicator( + const VideoProgressIndicator( this.controller, { this.colors = const VideoProgressColors(), required this.allowScrubbing, @@ -923,7 +924,7 @@ final int position = controller.value.position.inMilliseconds; int maxBuffering = 0; - for (DurationRange range in controller.value.buffered) { + for (final DurationRange range in controller.value.buffered) { final int end = range.end.inMilliseconds; if (end > maxBuffering) { maxBuffering = end; @@ -1005,9 +1006,9 @@ @override Widget build(BuildContext context) { - final text = this.text; + final String? text = this.text; if (text == null || text.isEmpty) { - return SizedBox.shrink(); + return const SizedBox.shrink(); } final TextStyle effectiveTextStyle = textStyle ?? @@ -1019,14 +1020,14 @@ return Align( alignment: Alignment.bottomCenter, child: Padding( - padding: EdgeInsets.only(bottom: 24.0), + padding: const EdgeInsets.only(bottom: 24.0), child: DecoratedBox( decoration: BoxDecoration( - color: Color(0xB8000000), + color: const Color(0xB8000000), borderRadius: BorderRadius.circular(2.0), ), child: Padding( - padding: EdgeInsets.symmetric(horizontal: 2.0), + padding: const EdgeInsets.symmetric(horizontal: 2.0), child: Text(text, style: effectiveTextStyle), ), ),
diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index a444fc6..2f6e289 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml
@@ -3,7 +3,7 @@ widgets on Android, iOS, and web. repository: https://github.com/flutter/plugins/tree/main/packages/video_player/video_player issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.2.18 +version: 2.2.19 environment: sdk: ">=2.14.0 <3.0.0" @@ -22,13 +22,12 @@ dependencies: flutter: sdk: flutter + html: ^0.15.0 video_player_android: ^2.2.17 video_player_avfoundation: ^2.2.17 video_player_platform_interface: ">=4.2.0 <6.0.0" video_player_web: ^2.0.0 - html: ^0.15.0 dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.10.0
diff --git a/packages/video_player/video_player/test/closed_caption_file_test.dart b/packages/video_player/video_player/test/closed_caption_file_test.dart index 369a3b3..b5c0a8e 100644 --- a/packages/video_player/video_player/test/closed_caption_file_test.dart +++ b/packages/video_player/video_player/test/closed_caption_file_test.dart
@@ -8,7 +8,7 @@ void main() { group('ClosedCaptionFile', () { test('toString()', () { - final Caption caption = const Caption( + const Caption caption = Caption( number: 1, start: Duration(seconds: 1), end: Duration(seconds: 2),
diff --git a/packages/video_player/video_player/test/sub_rip_file_test.dart b/packages/video_player/video_player/test/sub_rip_file_test.dart index 5808e0b..ea3bfda 100644 --- a/packages/video_player/video_player/test/sub_rip_file_test.dart +++ b/packages/video_player/video_player/test/sub_rip_file_test.dart
@@ -14,19 +14,19 @@ final Caption firstCaption = parsedFile.captions.first; expect(firstCaption.number, 1); - expect(firstCaption.start, Duration(seconds: 6)); - expect(firstCaption.end, Duration(seconds: 12, milliseconds: 74)); + expect(firstCaption.start, const Duration(seconds: 6)); + expect(firstCaption.end, const Duration(seconds: 12, milliseconds: 74)); expect(firstCaption.text, 'This is a test file'); final Caption secondCaption = parsedFile.captions[1]; expect(secondCaption.number, 2); expect( secondCaption.start, - Duration(minutes: 1, seconds: 54, milliseconds: 724), + const Duration(minutes: 1, seconds: 54, milliseconds: 724), ); expect( secondCaption.end, - Duration(minutes: 1, seconds: 56, milliseconds: 760), + const Duration(minutes: 1, seconds: 56, milliseconds: 760), ); expect(secondCaption.text, '- Hello.\n- Yes?'); @@ -34,11 +34,11 @@ expect(thirdCaption.number, 3); expect( thirdCaption.start, - Duration(minutes: 1, seconds: 56, milliseconds: 884), + const Duration(minutes: 1, seconds: 56, milliseconds: 884), ); expect( thirdCaption.end, - Duration(minutes: 1, seconds: 58, milliseconds: 954), + const Duration(minutes: 1, seconds: 58, milliseconds: 954), ); expect( thirdCaption.text, @@ -49,11 +49,11 @@ expect(fourthCaption.number, 4); expect( fourthCaption.start, - Duration(hours: 1, minutes: 1, seconds: 59, milliseconds: 84), + const Duration(hours: 1, minutes: 1, seconds: 59, milliseconds: 84), ); expect( fourthCaption.end, - Duration(hours: 1, minutes: 2, seconds: 1, milliseconds: 552), + const Duration(hours: 1, minutes: 2, seconds: 1, milliseconds: 552), ); expect( fourthCaption.text, @@ -68,8 +68,8 @@ final Caption firstCaption = parsedFile.captions.single; expect(firstCaption.number, 2); - expect(firstCaption.start, Duration(seconds: 15)); - expect(firstCaption.end, Duration(seconds: 17, milliseconds: 74)); + expect(firstCaption.start, const Duration(seconds: 15)); + expect(firstCaption.end, const Duration(seconds: 17, milliseconds: 74)); expect(firstCaption.text, 'This one is valid'); }); }
diff --git a/packages/video_player/video_player/test/video_player_initialization_test.dart b/packages/video_player/video_player/test/video_player_initialization_test.dart index 1870934..af0886f 100644 --- a/packages/video_player/video_player/test/video_player_initialization_test.dart +++ b/packages/video_player/video_player/test/video_player_initialization_test.dart
@@ -13,7 +13,8 @@ // in this file. test('plugin initialized', () async { TestWidgetsFlutterBinding.ensureInitialized(); - FakeVideoPlayerPlatform fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + final FakeVideoPlayerPlatform fakeVideoPlayerPlatform = + FakeVideoPlayerPlatform(); VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; final VideoPlayerController controller = VideoPlayerController.network(
diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart index 3bce821..07afd0f 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart
@@ -29,7 +29,7 @@ String get dataSource => ''; @override - Map<String, String> get httpHeaders => {}; + Map<String, String> get httpHeaders => <String, String>{}; @override DataSourceType get dataSourceType => DataSourceType.file; @@ -81,13 +81,13 @@ @override List<Caption> get captions { return <Caption>[ - Caption( + const Caption( text: 'one', number: 0, start: Duration(milliseconds: 100), end: Duration(milliseconds: 200), ), - Caption( + const Caption( text: 'two', number: 1, start: Duration(milliseconds: 300), @@ -135,8 +135,9 @@ group('ClosedCaption widget', () { testWidgets('uses a default text style', (WidgetTester tester) async { - final String text = 'foo'; - await tester.pumpWidget(MaterialApp(home: ClosedCaption(text: text))); + const String text = 'foo'; + await tester + .pumpWidget(const MaterialApp(home: ClosedCaption(text: text))); final Text textWidget = tester.widget<Text>(find.text(text)); expect(textWidget.style!.fontSize, 36.0); @@ -144,9 +145,9 @@ }); testWidgets('uses given text and style', (WidgetTester tester) async { - final String text = 'foo'; - final TextStyle textStyle = TextStyle(fontSize: 14.725); - await tester.pumpWidget(MaterialApp( + const String text = 'foo'; + const TextStyle textStyle = TextStyle(fontSize: 14.725); + await tester.pumpWidget(const MaterialApp( home: ClosedCaption( text: text, textStyle: textStyle, @@ -159,19 +160,20 @@ }); testWidgets('handles null text', (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp(home: ClosedCaption(text: null))); + await tester + .pumpWidget(const MaterialApp(home: ClosedCaption(text: null))); expect(find.byType(Text), findsNothing); }); testWidgets('handles empty text', (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp(home: ClosedCaption(text: ''))); + await tester.pumpWidget(const MaterialApp(home: ClosedCaption(text: ''))); expect(find.byType(Text), findsNothing); }); testWidgets('Passes text contrast ratio guidelines', (WidgetTester tester) async { - final String text = 'foo'; - await tester.pumpWidget(MaterialApp( + const String text = 'foo'; + await tester.pumpWidget(const MaterialApp( home: Scaffold( backgroundColor: Colors.white, body: ClosedCaption(text: text), @@ -218,7 +220,7 @@ ); expect( fakeVideoPlayerPlatform.dataSources[0].httpHeaders, - {}, + <String, String>{}, ); }); @@ -246,7 +248,7 @@ test('network with some headers', () async { final VideoPlayerController controller = VideoPlayerController.network( 'https://127.0.0.1', - httpHeaders: {'Authorization': 'Bearer token'}, + httpHeaders: <String, String>{'Authorization': 'Bearer token'}, ); await controller.initialize(); @@ -260,7 +262,7 @@ ); expect( fakeVideoPlayerPlatform.dataSources[0].httpHeaders, - {'Authorization': 'Bearer token'}, + <String, String>{'Authorization': 'Bearer token'}, ); }); @@ -269,10 +271,10 @@ 'http://testing.com/invalid_url', ); - late dynamic error; + late Object error; fakeVideoPlayerPlatform.forceInitError = true; - await controller.initialize().catchError((dynamic e) => error = e); - final PlatformException platformEx = error; + await controller.initialize().catchError((Object e) => error = e); + final PlatformException platformEx = error as PlatformException; expect(platformEx.code, equals('VideoError')); }); @@ -493,7 +495,7 @@ 'https://127.0.0.1', ); await controller.initialize(); - final progressWidget = + final VideoProgressIndicator progressWidget = VideoProgressIndicator(controller, allowScrubbing: true); await tester.pumpWidget(Directionality( @@ -505,7 +507,7 @@ expect(controller.value.isPlaying, isTrue); final Rect progressRect = tester.getRect(find.byWidget(progressWidget)); - await tester.dragFrom(progressRect.center, Offset(1.0, 0.0)); + await tester.dragFrom(progressRect.center, const Offset(1.0, 0.0)); await tester.pumpAndSettle(); expect(controller.value.position, lessThan(controller.value.duration)); @@ -520,7 +522,7 @@ 'https://127.0.0.1', ); await controller.initialize(); - final progressWidget = + final VideoProgressIndicator progressWidget = VideoProgressIndicator(controller, allowScrubbing: true); await tester.pumpWidget(Directionality( @@ -580,7 +582,7 @@ ); await controller.initialize(); - controller.setCaptionOffset(Duration(milliseconds: 100)); + controller.setCaptionOffset(const Duration(milliseconds: 100)); expect(controller.value.position, const Duration()); expect(controller.value.caption.text, ''); @@ -616,7 +618,7 @@ ); await controller.initialize(); - controller.setCaptionOffset(Duration(milliseconds: -100)); + controller.setCaptionOffset(const Duration(milliseconds: -100)); expect(controller.value.position, const Duration()); expect(controller.value.caption.text, ''); @@ -688,12 +690,11 @@ const Duration bufferStart = Duration(seconds: 0); const Duration bufferEnd = Duration(milliseconds: 500); - fakeVideoEventStream - ..add(VideoEvent( - eventType: VideoEventType.bufferingUpdate, - buffered: <DurationRange>[ - DurationRange(bufferStart, bufferEnd), - ])); + fakeVideoEventStream.add(VideoEvent( + eventType: VideoEventType.bufferingUpdate, + buffered: <DurationRange>[ + DurationRange(bufferStart, bufferEnd), + ])); await tester.pumpAndSettle(); expect(controller.value.isBuffering, isTrue); expect(controller.value.buffered.length, 1); @@ -854,45 +855,45 @@ group('aspectRatio', () { test('640x480 -> 4:3', () { - final value = VideoPlayerValue( + final VideoPlayerValue value = VideoPlayerValue( isInitialized: true, - size: Size(640, 480), - duration: Duration(seconds: 1), + size: const Size(640, 480), + duration: const Duration(seconds: 1), ); expect(value.aspectRatio, 4 / 3); }); test('no size -> 1.0', () { - final value = VideoPlayerValue( + final VideoPlayerValue value = VideoPlayerValue( isInitialized: true, - duration: Duration(seconds: 1), + duration: const Duration(seconds: 1), ); expect(value.aspectRatio, 1.0); }); test('height = 0 -> 1.0', () { - final value = VideoPlayerValue( + final VideoPlayerValue value = VideoPlayerValue( isInitialized: true, - size: Size(640, 0), - duration: Duration(seconds: 1), + size: const Size(640, 0), + duration: const Duration(seconds: 1), ); expect(value.aspectRatio, 1.0); }); test('width = 0 -> 1.0', () { - final value = VideoPlayerValue( + final VideoPlayerValue value = VideoPlayerValue( isInitialized: true, - size: Size(0, 480), - duration: Duration(seconds: 1), + size: const Size(0, 480), + duration: const Duration(seconds: 1), ); expect(value.aspectRatio, 1.0); }); test('negative aspect ratio -> 1.0', () { - final value = VideoPlayerValue( + final VideoPlayerValue value = VideoPlayerValue( isInitialized: true, - size: Size(640, -480), - duration: Duration(seconds: 1), + size: const Size(640, -480), + duration: const Duration(seconds: 1), ); expect(value.aspectRatio, 1.0); }); @@ -904,7 +905,7 @@ const Color bufferedColor = Color.fromRGBO(0, 255, 0, 0.5); const Color backgroundColor = Color.fromRGBO(255, 255, 0, 0.25); - final VideoProgressColors colors = VideoProgressColors( + const VideoProgressColors colors = VideoProgressColors( playedColor: playedColor, bufferedColor: bufferedColor, backgroundColor: backgroundColor); @@ -936,7 +937,7 @@ @override Future<int?> create(DataSource dataSource) async { calls.add('create'); - StreamController<VideoEvent> stream = StreamController<VideoEvent>(); + final StreamController<VideoEvent> stream = StreamController<VideoEvent>(); streams[nextTextureId] = stream; if (forceInitError) { stream.addError(PlatformException( @@ -944,8 +945,8 @@ } else { stream.add(VideoEvent( eventType: VideoEventType.initialized, - size: Size(100, 100), - duration: Duration(seconds: 1))); + size: const Size(100, 100), + duration: const Duration(seconds: 1))); } dataSources.add(dataSource); return nextTextureId++; @@ -962,6 +963,7 @@ initialized.complete(true); } + @override Stream<VideoEvent> videoEventsFor(int textureId) { return streams[textureId]!.stream; }
diff --git a/packages/video_player/video_player/test/web_vtt_test.dart b/packages/video_player/video_player/test/web_vtt_test.dart index 59fce98..bde6292 100644 --- a/packages/video_player/video_player/test/web_vtt_test.dart +++ b/packages/video_player/video_player/test/web_vtt_test.dart
@@ -14,9 +14,9 @@ parsedFile = WebVTTCaptionFile(_valid_vtt_with_metadata); expect(parsedFile.captions.length, 1); - expect(parsedFile.captions[0].start, Duration(seconds: 1)); - expect( - parsedFile.captions[0].end, Duration(seconds: 2, milliseconds: 500)); + expect(parsedFile.captions[0].start, const Duration(seconds: 1)); + expect(parsedFile.captions[0].end, + const Duration(seconds: 2, milliseconds: 500)); expect(parsedFile.captions[0].text, 'We are in New York City'); }); @@ -25,11 +25,11 @@ expect(parsedFile.captions.length, 1); expect(parsedFile.captions[0].start, - Duration(seconds: 2, milliseconds: 800)); - expect( - parsedFile.captions[0].end, Duration(seconds: 3, milliseconds: 283)); + const Duration(seconds: 2, milliseconds: 800)); + expect(parsedFile.captions[0].end, + const Duration(seconds: 3, milliseconds: 283)); expect(parsedFile.captions[0].text, - "— It will perforate your stomach.\n— You could die."); + '— It will perforate your stomach.\n— You could die.'); }); test('with styles tags', () { @@ -37,9 +37,9 @@ expect(parsedFile.captions.length, 3); expect(parsedFile.captions[0].start, - Duration(seconds: 5, milliseconds: 200)); - expect( - parsedFile.captions[0].end, Duration(seconds: 6, milliseconds: 000)); + const Duration(seconds: 5, milliseconds: 200)); + expect(parsedFile.captions[0].end, + const Duration(seconds: 6, milliseconds: 000)); expect(parsedFile.captions[0].text, "You know I'm so excited my glasses are falling off here."); }); @@ -49,9 +49,9 @@ expect(parsedFile.captions.length, 3); expect(parsedFile.captions[0].number, 1); - expect(parsedFile.captions.last.start, Duration(seconds: 4)); - expect(parsedFile.captions.last.end, Duration(seconds: 5)); - expect(parsedFile.captions.last.text, "Transcrit par Célestes™"); + expect(parsedFile.captions.last.start, const Duration(seconds: 4)); + expect(parsedFile.captions.last.end, const Duration(seconds: 5)); + expect(parsedFile.captions.last.text, 'Transcrit par Célestes™'); }); test('with [hours]:[minutes]:[seconds].[milliseconds].', () { @@ -59,9 +59,9 @@ expect(parsedFile.captions.length, 1); expect(parsedFile.captions[0].number, 1); - expect(parsedFile.captions.last.start, Duration(seconds: 1)); - expect(parsedFile.captions.last.end, Duration(seconds: 2)); - expect(parsedFile.captions.last.text, "This is a test."); + expect(parsedFile.captions.last.start, const Duration(seconds: 1)); + expect(parsedFile.captions.last.end, const Duration(seconds: 2)); + expect(parsedFile.captions.last.text, 'This is a test.'); }); test('with [minutes]:[seconds].[milliseconds].', () { @@ -69,9 +69,9 @@ expect(parsedFile.captions.length, 1); expect(parsedFile.captions[0].number, 1); - expect(parsedFile.captions.last.start, Duration(seconds: 3)); - expect(parsedFile.captions.last.end, Duration(seconds: 4)); - expect(parsedFile.captions.last.text, "This is a test."); + expect(parsedFile.captions.last.start, const Duration(seconds: 3)); + expect(parsedFile.captions.last.end, const Duration(seconds: 4)); + expect(parsedFile.captions.last.text, 'This is a test.'); }); test('with invalid seconds format returns empty captions.', () { @@ -105,8 +105,8 @@ final Caption firstCaption = parsedFile.captions.single; expect(firstCaption.number, 1); - expect(firstCaption.start, Duration(seconds: 13)); - expect(firstCaption.end, Duration(seconds: 16, milliseconds: 0)); + expect(firstCaption.start, const Duration(seconds: 13)); + expect(firstCaption.end, const Duration(seconds: 16, milliseconds: 0)); expect(firstCaption.text, 'Valid'); }); }
diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml index d10424e..71f6f03 100644 --- a/script/configs/custom_analysis.yaml +++ b/script/configs/custom_analysis.yaml
@@ -17,4 +17,3 @@ - in_app_purchase/in_app_purchase - in_app_purchase/in_app_purchase_android - in_app_purchase/in_app_purchase_storekit -- video_player/video_player