From 2b91881248d7cd7cbf68f2ecdf233674865e6158 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Jan 2023 16:41:48 -0500 Subject: [PATCH 1/3] [cross_file] Fix accidental constructor change In https://github.com/flutter/packages/pull/3095 I accidentally changed a constructor argument's nullability because of a misleading analyzer warning. That version has been retracted; this restores the original behavior. --- packages/cross_file/CHANGELOG.md | 5 +++++ packages/cross_file/lib/src/types/interface.dart | 6 ++++-- packages/cross_file/pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/cross_file/CHANGELOG.md b/packages/cross_file/CHANGELOG.md index a001f20c45cd..fb2efd3f1c1d 100644 --- a/packages/cross_file/CHANGELOG.md +++ b/packages/cross_file/CHANGELOG.md @@ -1,5 +1,10 @@ +## 0.3.3+4 + +* Reverts an accidental change in a constructor argument's nullability. + ## 0.3.3+3 +* **RETRACTED** * Updates code to fix strict-cast violations. * Updates minimum SDK version to Flutter 3.0. diff --git a/packages/cross_file/lib/src/types/interface.dart b/packages/cross_file/lib/src/types/interface.dart index 3243d88061c6..b9811c83a247 100644 --- a/packages/cross_file/lib/src/types/interface.dart +++ b/packages/cross_file/lib/src/types/interface.dart @@ -21,15 +21,17 @@ class XFile extends XFileBase { /// `name` may be passed from the outside, for those cases where the effective /// `path` of the file doesn't match what the user sees when selecting it /// (like in web) + // This is a false positive; super.path is a String?, not a String. + // ignore: use_super_parameters XFile( - super.path, { + String path, { String? mimeType, String? name, int? length, Uint8List? bytes, DateTime? lastModified, @visibleForTesting CrossFileTestOverrides? overrides, - }) { + }) : super(path) { throw UnimplementedError( 'CrossFile is not available in your current platform.'); } diff --git a/packages/cross_file/pubspec.yaml b/packages/cross_file/pubspec.yaml index 099b914aa1f2..e46c255ae281 100644 --- a/packages/cross_file/pubspec.yaml +++ b/packages/cross_file/pubspec.yaml @@ -2,7 +2,7 @@ name: cross_file description: An abstraction to allow working with files across multiple platforms. repository: https://github.com/flutter/packages/tree/main/packages/cross_file issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22 -version: 0.3.3+3 +version: 0.3.3+4 environment: sdk: ">=2.17.0 <3.0.0" From 29308e6930aca0616f5bea133595455ef3e06ea3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Jan 2023 16:52:29 -0500 Subject: [PATCH 2/3] Add a test --- packages/cross_file/test/x_file_io_test.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart index 4a676e2f880f..7b730ca76553 100644 --- a/packages/cross_file/test/x_file_io_test.dart +++ b/packages/cross_file/test/x_file_io_test.dart @@ -70,6 +70,10 @@ void main() { await tempDir.delete(recursive: true); }); + + test('nullability is correct', () async { + expect(_ensureNonnullPathArgument('a/path'), isNotNull); + }); }); group('Create with data', () { @@ -107,6 +111,13 @@ void main() { }); } +// This is to create an analysis error if the version of XFile in +// interface.dart, which should never actually be used but is what the analyzer +// runs against, has the nullability of `path` changed. +XFile _ensureNonnullPathArgument(String? path) { + return XFile(path!); +} + /// An XFile subclass that tracks reads, for testing purposes. class TestXFile extends XFile { TestXFile(super.path); From 42711f3a42645f66142ed046c1e3954d7c09efc5 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 1 Feb 2023 07:55:45 -0500 Subject: [PATCH 3/3] Better implementation --- packages/cross_file/lib/src/types/interface.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/cross_file/lib/src/types/interface.dart b/packages/cross_file/lib/src/types/interface.dart index b9811c83a247..c83e5734d329 100644 --- a/packages/cross_file/lib/src/types/interface.dart +++ b/packages/cross_file/lib/src/types/interface.dart @@ -21,17 +21,15 @@ class XFile extends XFileBase { /// `name` may be passed from the outside, for those cases where the effective /// `path` of the file doesn't match what the user sees when selecting it /// (like in web) - // This is a false positive; super.path is a String?, not a String. - // ignore: use_super_parameters XFile( - String path, { + String super.path, { String? mimeType, String? name, int? length, Uint8List? bytes, DateTime? lastModified, @visibleForTesting CrossFileTestOverrides? overrides, - }) : super(path) { + }) { throw UnimplementedError( 'CrossFile is not available in your current platform.'); }