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

Commit

Permalink
[video_player] Migrate video player to null safety (#3165)
Browse files Browse the repository at this point in the history
* Migrate video player to null safety

* Fixes

* Double quotes -> single quotes

* Format and lint

* feedback

* Test example app

* Fix analyzer
  • Loading branch information
Emmanuel Garcia committed Oct 20, 2020
1 parent 5b049f4 commit 7dd61d9
Show file tree
Hide file tree
Showing 26 changed files with 248 additions and 178 deletions.
4 changes: 4 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.0

* Migration to null safety.

## 0.11.1+2

* Update android compileSdkVersion to 29.
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Duration _playDuration = Duration(seconds: 1);

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
VideoPlayerController _controller;
late VideoPlayerController _controller;
tearDown(() async => _controller.dispose());

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

expect(_controller.value.initialized, true);
expect(_controller.value.isInitialized, true);
expect(_controller.value.position, const Duration(seconds: 0));
expect(_controller.value.isPlaying, false);
expect(_controller.value.duration,
Expand Down
11 changes: 6 additions & 5 deletions packages/video_player/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _ButterFlyAssetVideoInList extends StatelessWidget {

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

final String title;

Expand Down Expand Up @@ -150,7 +150,7 @@ class _ButterFlyAssetVideo extends StatefulWidget {
}

class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
VideoPlayerController _controller;
late VideoPlayerController _controller;

@override
void initState() {
Expand Down Expand Up @@ -206,7 +206,7 @@ class _BumbleBeeRemoteVideo extends StatefulWidget {
}

class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
VideoPlayerController _controller;
late VideoPlayerController _controller;

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

class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({Key key, this.controller}) : super(key: key);
const _ControlsOverlay({Key? key, required this.controller})
: super(key: key);

static const _examplePlaybackRates = [
0.25,
Expand Down Expand Up @@ -345,7 +346,7 @@ class _PlayerVideoAndPopPage extends StatefulWidget {
}

class _PlayerVideoAndPopPageState extends State<_PlayerVideoAndPopPage> {
VideoPlayerController _videoPlayerController;
late VideoPlayerController _videoPlayerController;
bool startedPlaying = false;

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dev_dependencies:
integration_test:
path: ../../../integration_test
test: any
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety.1

flutter:
uses-material-design: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'package:flutter_driver/driver_extension.dart';
import 'package:video_player_example/main.dart' as app;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'dart:async';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class Caption {
///
/// This is not recommended for direct use unless you are writing a parser for
/// a new closed captioning file type.
const Caption({this.number, this.start, this.end, this.text});
const Caption(
{required this.number,
required this.start,
required this.end,
required this.text});

/// The number that this caption was assigned.
final int number;
Expand All @@ -45,4 +49,9 @@ class Caption {
/// The actual text that should appear on screen to be read between [start]
/// and [end].
final String text;

/// A no caption object. This is a caption with [start] and [end] durations of zero,
/// and an empty [text] string.
static const Caption none =
Caption(number: 0, start: Duration.zero, end: Duration.zero, text: '');
}
7 changes: 3 additions & 4 deletions packages/video_player/video_player/lib/src/sub_rip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ List<Caption> _parseCaptionsFromSubRipString(String file) {
end: startAndEnd.end,
text: text,
);

if (newCaption.start != null && newCaption.end != null) {
if (newCaption.start != newCaption.end) {
captions.add(newCaption);
}
}
Expand All @@ -64,7 +63,7 @@ class _StartAndEnd {
RegExp(_subRipTimeStamp + _subRipArrow + _subRipTimeStamp);

if (!format.hasMatch(line)) {
return _StartAndEnd(null, null);
return _StartAndEnd(Duration.zero, Duration.zero);
}

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

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

0 comments on commit 7dd61d9

Please sign in to comment.