Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 7dd61d9

Browse files
author
Emmanuel Garcia
authored
[video_player] Migrate video player to null safety (#3165)
* Migrate video player to null safety * Fixes * Double quotes -> single quotes * Format and lint * feedback * Test example app * Fix analyzer
1 parent 5b049f4 commit 7dd61d9

26 files changed

+248
-178
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.12.0
2+
3+
* Migration to null safety.
4+
15
## 0.11.1+2
26

37
* Update android compileSdkVersion to 29.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: ../../../analysis_options.yaml
2+
analyzer:
3+
enable-experiment:
4+
- non-nullable

packages/video_player/video_player/example/integration_test/video_player_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Duration _playDuration = Duration(seconds: 1);
1111

1212
void main() {
1313
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
14-
VideoPlayerController _controller;
14+
late VideoPlayerController _controller;
1515
tearDown(() async => _controller.dispose());
1616

1717
group('asset videos', () {
@@ -22,7 +22,7 @@ void main() {
2222
testWidgets('can be initialized', (WidgetTester tester) async {
2323
await _controller.initialize();
2424

25-
expect(_controller.value.initialized, true);
25+
expect(_controller.value.isInitialized, true);
2626
expect(_controller.value.position, const Duration(seconds: 0));
2727
expect(_controller.value.isPlaying, false);
2828
expect(_controller.value.duration,

packages/video_player/video_player/example/lib/main.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class _ButterFlyAssetVideoInList extends StatelessWidget {
108108

109109
/// A filler card to show the video in a list of scrolling contents.
110110
class _ExampleCard extends StatelessWidget {
111-
const _ExampleCard({Key key, this.title}) : super(key: key);
111+
const _ExampleCard({Key? key, required this.title}) : super(key: key);
112112

113113
final String title;
114114

@@ -150,7 +150,7 @@ class _ButterFlyAssetVideo extends StatefulWidget {
150150
}
151151

152152
class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
153-
VideoPlayerController _controller;
153+
late VideoPlayerController _controller;
154154

155155
@override
156156
void initState() {
@@ -206,7 +206,7 @@ class _BumbleBeeRemoteVideo extends StatefulWidget {
206206
}
207207

208208
class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
209-
VideoPlayerController _controller;
209+
late VideoPlayerController _controller;
210210

211211
Future<ClosedCaptionFile> _loadCaptions() async {
212212
final String fileContents = await DefaultAssetBundle.of(context)
@@ -265,7 +265,8 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
265265
}
266266

267267
class _ControlsOverlay extends StatelessWidget {
268-
const _ControlsOverlay({Key key, this.controller}) : super(key: key);
268+
const _ControlsOverlay({Key? key, required this.controller})
269+
: super(key: key);
269270

270271
static const _examplePlaybackRates = [
271272
0.25,
@@ -345,7 +346,7 @@ class _PlayerVideoAndPopPage extends StatefulWidget {
345346
}
346347

347348
class _PlayerVideoAndPopPageState extends State<_PlayerVideoAndPopPage> {
348-
VideoPlayerController _videoPlayerController;
349+
late VideoPlayerController _videoPlayerController;
349350
bool startedPlaying = false;
350351

351352
@override

packages/video_player/video_player/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dev_dependencies:
1515
integration_test:
1616
path: ../../../integration_test
1717
test: any
18-
pedantic: ^1.8.0
18+
pedantic: ^1.10.0-nullsafety.1
1919

2020
flutter:
2121
uses-material-design: true

packages/video_player/video_player/example/test_driver/integration_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
6+
// @dart = 2.9
7+
58
import 'dart:async';
69
import 'dart:convert';
710
import 'dart:io';

packages/video_player/video_player/example/test_driver/video_player.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
6+
// @dart = 2.9
7+
58
import 'package:flutter_driver/driver_extension.dart';
69
import 'package:video_player_example/main.dart' as app;
710

packages/video_player/video_player/example/test_driver/video_player_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
6+
// @dart = 2.9
7+
58
import 'dart:async';
69
import 'package:flutter_driver/flutter_driver.dart';
710
import 'package:test/test.dart';

packages/video_player/video_player/lib/src/closed_caption_file.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class Caption {
3131
///
3232
/// This is not recommended for direct use unless you are writing a parser for
3333
/// a new closed captioning file type.
34-
const Caption({this.number, this.start, this.end, this.text});
34+
const Caption(
35+
{required this.number,
36+
required this.start,
37+
required this.end,
38+
required this.text});
3539

3640
/// The number that this caption was assigned.
3741
final int number;
@@ -45,4 +49,9 @@ class Caption {
4549
/// The actual text that should appear on screen to be read between [start]
4650
/// and [end].
4751
final String text;
52+
53+
/// A no caption object. This is a caption with [start] and [end] durations of zero,
54+
/// and an empty [text] string.
55+
static const Caption none =
56+
Caption(number: 0, start: Duration.zero, end: Duration.zero, text: '');
4857
}

packages/video_player/video_player/lib/src/sub_rip.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ List<Caption> _parseCaptionsFromSubRipString(String file) {
4141
end: startAndEnd.end,
4242
text: text,
4343
);
44-
45-
if (newCaption.start != null && newCaption.end != null) {
44+
if (newCaption.start != newCaption.end) {
4645
captions.add(newCaption);
4746
}
4847
}
@@ -64,7 +63,7 @@ class _StartAndEnd {
6463
RegExp(_subRipTimeStamp + _subRipArrow + _subRipTimeStamp);
6564

6665
if (!format.hasMatch(line)) {
67-
return _StartAndEnd(null, null);
66+
return _StartAndEnd(Duration.zero, Duration.zero);
6867
}
6968

7069
final List<String> times = line.split(_subRipArrow);
@@ -84,7 +83,7 @@ class _StartAndEnd {
8483
// Duration(hours: 0, minutes: 1, seconds: 59, milliseconds: 084)
8584
Duration _parseSubRipTimestamp(String timestampString) {
8685
if (!RegExp(_subRipTimeStamp).hasMatch(timestampString)) {
87-
return null;
86+
return Duration.zero;
8887
}
8988

9089
final List<String> commaSections = timestampString.split(',');

0 commit comments

Comments
 (0)