Implementing null-aware operators throughout the repository (#143804)

This pull request fixes #143803 by taking advantage of Dart's null-aware operators.

And unlike `switch` expressions ([9 PRs](https://github.com/flutter/flutter/pull/143634) and counting), the Flutter codebase is already fantastic when it comes to null-aware coding. After refactoring the entire repo, all the changes involving `?.` and `??` can fit into a single pull request.
This commit is contained in:
Nate
2024-02-23 12:02:22 -07:00
committed by GitHub
parent 39585e66c1
commit c53a18f4e4
55 changed files with 93 additions and 365 deletions

View File

@@ -24,90 +24,60 @@ class FlutterIOOverrides extends io.IOOverrides {
@override
io.Directory createDirectory(String path) {
if (_fileSystemDelegate == null) {
return super.createDirectory(path);
}
return _fileSystemDelegate.directory(path);
return _fileSystemDelegate?.directory(path) ?? super.createDirectory(path);
}
@override
io.File createFile(String path) {
if (_fileSystemDelegate == null) {
return super.createFile(path);
}
return _fileSystemDelegate.file(path);
return _fileSystemDelegate?.file(path) ?? super.createFile(path);
}
@override
io.Link createLink(String path) {
if (_fileSystemDelegate == null) {
return super.createLink(path);
}
return _fileSystemDelegate.link(path);
return _fileSystemDelegate?.link(path) ?? super.createLink(path);
}
@override
Stream<FileSystemEvent> fsWatch(String path, int events, bool recursive) {
if (_fileSystemDelegate == null) {
return super.fsWatch(path, events, recursive);
}
return _fileSystemDelegate.file(path).watch(events: events, recursive: recursive);
return _fileSystemDelegate?.file(path).watch(events: events, recursive: recursive)
?? super.fsWatch(path, events, recursive);
}
@override
bool fsWatchIsSupported() {
if (_fileSystemDelegate == null) {
return super.fsWatchIsSupported();
}
return _fileSystemDelegate.isWatchSupported;
return _fileSystemDelegate?.isWatchSupported ?? super.fsWatchIsSupported();
}
@override
Future<FileSystemEntityType> fseGetType(String path, bool followLinks) {
if (_fileSystemDelegate == null) {
return super.fseGetType(path, followLinks);
}
return _fileSystemDelegate.type(path, followLinks: followLinks);
return _fileSystemDelegate?.type(path, followLinks: followLinks)
?? super.fseGetType(path, followLinks);
}
@override
FileSystemEntityType fseGetTypeSync(String path, bool followLinks) {
if (_fileSystemDelegate == null) {
return super.fseGetTypeSync(path, followLinks);
}
return _fileSystemDelegate.typeSync(path, followLinks: followLinks);
return _fileSystemDelegate?.typeSync(path, followLinks: followLinks)
?? super.fseGetTypeSync(path, followLinks);
}
@override
Future<bool> fseIdentical(String path1, String path2) {
if (_fileSystemDelegate == null) {
return super.fseIdentical(path1, path2);
}
return _fileSystemDelegate.identical(path1, path2);
return _fileSystemDelegate?.identical(path1, path2) ?? super.fseIdentical(path1, path2);
}
@override
bool fseIdenticalSync(String path1, String path2) {
if (_fileSystemDelegate == null) {
return super.fseIdenticalSync(path1, path2);
}
return _fileSystemDelegate.identicalSync(path1, path2);
return _fileSystemDelegate?.identicalSync(path1, path2) ?? super.fseIdenticalSync(path1, path2);
}
@override
io.Directory getCurrentDirectory() {
if (_fileSystemDelegate == null) {
return super.getCurrentDirectory();
}
return _fileSystemDelegate.currentDirectory;
return _fileSystemDelegate?.currentDirectory ?? super.getCurrentDirectory();
}
@override
io.Directory getSystemTempDirectory() {
if (_fileSystemDelegate == null) {
return super.getSystemTempDirectory();
}
return _fileSystemDelegate.systemTempDirectory;
return _fileSystemDelegate?.systemTempDirectory ?? super.getSystemTempDirectory();
}
@override
@@ -120,17 +90,11 @@ class FlutterIOOverrides extends io.IOOverrides {
@override
Future<FileStat> stat(String path) {
if (_fileSystemDelegate == null) {
return super.stat(path);
}
return _fileSystemDelegate.stat(path);
return _fileSystemDelegate?.stat(path) ?? super.stat(path);
}
@override
FileStat statSync(String path) {
if (_fileSystemDelegate == null) {
return super.statSync(path);
}
return _fileSystemDelegate.statSync(path);
return _fileSystemDelegate?.statSync(path) ?? super.statSync(path);
}
}