[cross_file] Fix accidental constructor change (#3131)
* [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.
* Add a test
* Better implementation
diff --git a/packages/cross_file/CHANGELOG.md b/packages/cross_file/CHANGELOG.md
index a001f20..fb2efd3 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 3243d88..c83e573 100644
--- a/packages/cross_file/lib/src/types/interface.dart
+++ b/packages/cross_file/lib/src/types/interface.dart
@@ -22,7 +22,7 @@
/// `path` of the file doesn't match what the user sees when selecting it
/// (like in web)
XFile(
- super.path, {
+ String super.path, {
String? mimeType,
String? name,
int? length,
diff --git a/packages/cross_file/pubspec.yaml b/packages/cross_file/pubspec.yaml
index 099b914..e46c255 100644
--- a/packages/cross_file/pubspec.yaml
+++ b/packages/cross_file/pubspec.yaml
@@ -2,7 +2,7 @@
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"
diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart
index 4a676e2..7b730ca 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 @@
await tempDir.delete(recursive: true);
});
+
+ test('nullability is correct', () async {
+ expect(_ensureNonnullPathArgument('a/path'), isNotNull);
+ });
});
group('Create with data', () {
@@ -107,6 +111,13 @@
});
}
+// 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);