Skip to content
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

fix Cannot access null value from map #217

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

apps-auth
Copy link

This pull resolve problem of acess maps keys of null or undefinded.
This bellow example, with old code, return error in "lib\src\eval\runtime\ops\objects.dart" in line 100:

final method = ((object as $Instance).$getProperty(runtime, _method) as EvalFunction);

Throw error is "object" is null, not $Instance

Example code for replicate error:

Future<dynamic> main(Map<String, dynamic> args) async {
  Map<String, dynamic> object = {
    "key1": "value1",
    "key2": "value2",
  };

  int value3 = 1;

  num? _value3 = object['key3'];

  print("_value3: $_value3"); //null
  print("_value3 != null: ${_value3 != null}"); //_value3 != null: true

  if (_value3 != null) {
    value3 = _value3.toInt();
  }

  print("value3: $value3"); //1
}

@apps-auth
Copy link
Author

Hello
In addition to fixing the problem with accessing the null value of the Map, I continue to implement other features

@ghost
Copy link

ghost commented Oct 13, 2024

Hello @apps-auth. Very rookie dev here so I imagine I am doing this incorrectly... Still wrapping my brain around all this and trying to use dart_eval for a FlutterFlow project. I noticed somewhere it seems like you made a bit of a change to class $String implements $Instance...

...I had a problem with the second pub.dev readme where it said that $String() didn't exist.

Does this change solve that problem or am I completely out to lunch and the readme should be perfectly implementable?

@ethanblake4
Copy link
Owner

ethanblake4 commented Nov 6, 2024

Hi, I appreciate your effort here. The Map.from and toDouble changes look great.

Unfortunately, checks like is $Value and ?? $null() are generally problematic and almost always incorrect. Typically they only use the runtime to mask the symptom of an underlying compiler issue. So, I cannot accept these changes. If you would like to make a separate PR for the Map.from and toDouble change I can accept those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants