Unverified Commit 5a21e2d8 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Make version and time in flutter_tool null safe (#78836)

parent 0bde67e7
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
/// A class for making time based operations testable. /// A class for making time based operations testable.
class SystemClock { class SystemClock {
/// A const constructor to allow subclasses to be const. /// A const constructor to allow subclasses to be const.
......
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
@immutable @immutable
class Version implements Comparable<Version> { class Version implements Comparable<Version> {
/// Creates a new [Version] object. /// Creates a new [Version] object.
factory Version(int major, int minor, int patch, {String text}) { factory Version(int? major, int? minor, int? patch, {String? text}) {
if (text == null) { if (text == null) {
text = major == null ? '0' : '$major'; text = major == null ? '0' : '$major';
if (minor != null) { if (minor != null) {
...@@ -36,8 +34,8 @@ class Version implements Comparable<Version> { ...@@ -36,8 +34,8 @@ class Version implements Comparable<Version> {
} }
/// Creates a new [Version] by parsing [text]. /// Creates a new [Version] by parsing [text].
factory Version.parse(String text) { static Version? parse(String? text) {
final Match match = versionPattern.firstMatch(text ?? ''); final Match? match = versionPattern.firstMatch(text ?? '');
if (match == null) { if (match == null) {
return null; return null;
} }
...@@ -46,7 +44,7 @@ class Version implements Comparable<Version> { ...@@ -46,7 +44,7 @@ class Version implements Comparable<Version> {
final int major = int.parse(match[1] ?? '0'); final int major = int.parse(match[1] ?? '0');
final int minor = int.parse(match[3] ?? '0'); final int minor = int.parse(match[3] ?? '0');
final int patch = int.parse(match[5] ?? '0'); final int patch = int.parse(match[5] ?? '0');
return Version._(major, minor, patch, text); return Version._(major, minor, patch, text ?? '');
} on FormatException { } on FormatException {
return null; return null;
} }
...@@ -55,8 +53,8 @@ class Version implements Comparable<Version> { ...@@ -55,8 +53,8 @@ class Version implements Comparable<Version> {
/// Returns the primary version out of a list of candidates. /// Returns the primary version out of a list of candidates.
/// ///
/// This is the highest-numbered stable version. /// This is the highest-numbered stable version.
static Version primary(List<Version> versions) { static Version? primary(List<Version> versions) {
Version primary; Version? primary;
for (final Version version in versions) { for (final Version version in versions) {
if (primary == null || (version > primary)) { if (primary == null || (version > primary)) {
primary = version; primary = version;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment