-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
type 'Null' is not a subtype of type 'String' #53700
Comments
Which tool are you using when you see this message without any information about where the error happened? |
Even with android studio or VS code |
I can reproduce the problem in DartPad, but when I run void main() {
Map<String, dynamic> map = {"name": "jeremie", "age": 12};
String sex = map['sex'];
print(sex);
} in VSCode, the following output is printed in the Debug Console:
The stack trace does indicate where the exception was thrown (on the line marked with I haven't tried to reproduce it in Android Studio, but I'd be surprised if it didn't provide you with the full stack trace. |
Thanks for the additional information. This is definitely an issue for DartPad, even without hot reload, but it appears to also be an issue for hot reload. |
I filed this issue for DartPad: dart-lang/dart-pad#2668 |
@bwilkerson Off topic, but do you know why the Flutter SDK prints a different error message in this scenario? Here's what is printed when the exception is thrown from a Flutter app:
And here's what the exception looks like if you use a Dart SDK:
|
No, I don't know why they're different. Obviously Flutter is catching the exception at some point and wrapping the message, but I would have expected the second line of Flutter's message to match what the Dart SDK is producing. Is it possible that you're using two different versions of the Dart SDK somehow? If not, I have no clue. |
@jeremielodi Can you share a small snippet that reproduces the issue? I can't reproduce this issue in Flutter after hot-reloading. I put the code you shared in the Snippet
|
Without additional information we're not able to resolve this issue. Feel free to add more info or respond to any questions above and we can reopen the case. Thanks for your contribution! |
I guess the real topic here is the lack of stack traces and other information. However, it's worth noting that the example is working as intended: void main() {
Map<String, dynamic> map = {"name": "jeremie", "age": 12};
String sex = map['sex']; // Throws.
print(sex);
} The exception is thrown when the line with the comment is reached because the type of the expression Nothing surprising about this, and everything is working as intended. However, if you wish to avoid this kind of dynamic type check then you can make sure that you have an 'analysis_options.yaml' file in the root of your package that contains at least the following: analyzer:
language:
strict-casts: true You'll find some extra information about these settings here. |
I had the same exception with code below:
|
I Suggest to have the file name and the line where has error happened. It's very complicated to know directly where to fixe the type when you face this error.
The text was updated successfully, but these errors were encountered: