-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Enable null safety by default in templates #78619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@munificent can you check to see if my changes are ideomatic? |
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look like some tool tests are failing.
packages/flutter_tools/templates/module/common/lib/main.dart.tmpl
Outdated
Show resolved
Hide resolved
|
|
||
| static Future<String> get platformVersion async { | ||
| final String version = await _channel.invokeMethod('getPlatformVersion'); | ||
| static Future<String?> get platformVersion async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this actually be allowed to return null? Or is null always an error case (e.g. plugin wasn't available).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this correctly, then MethodChannel can never return null, but OptionalMethodChannel can.
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/platform_channel.dart#L330
I think we know in MethodChannel that T is never null (as per missingOk: false), so we could change MethodChannel.invokeMethod to return Future<T> not Future<T?>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work:
diff --git a/packages/flutter/lib/src/services/platform_channel.dart b/packages/flutter/lib/src/services/platform_channel.dart
index c9bad0e210..bd07c68829 100644
--- a/packages/flutter/lib/src/services/platform_channel.dart
+++ b/packages/flutter/lib/src/services/platform_channel.dart
@@ -327,8 +327,8 @@ class MethodChannel {
/// * <https://api.flutter.dev/javadoc/io/flutter/plugin/common/MethodCall.html>
/// for how to access method call arguments on Android.
@optionalTypeArgs
- Future<T?> invokeMethod<T>(String method, [ dynamic arguments ]) {
- return _invokeMethod<T>(method, missingOk: false, arguments: arguments);
+ Future<T> invokeMethod<T>(String method, [ dynamic arguments ]) {
+ return _invokeMethod<T>(method, missingOk: false, arguments: arguments) as T;
}Who know this code best and can comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goderbauer WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like changing the interface requires a larger refactoring...
munificent
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dart changes look idiomatic to me.
|
CI is now passing (the red X is the Flutter Dashboard being red). |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tool changes LGTM
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
||
| static Future<String> get platformVersion async { | ||
| final String version = await _channel.invokeMethod('getPlatformVersion'); | ||
| static Future<String?> get platformVersion async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like changing the interface requires a larger refactoring...
Co-authored-by: Michael Goderbauer <goderbauer@google.com>
Enable Dart null safety (https://dart.dev/null-safety) by default in all
flutter createtemplates.