dart_eval icon indicating copy to clipboard operation
dart_eval copied to clipboard

fix Cannot access null value from map

Open apps-auth opened this issue 1 year ago • 3 comments

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 avatar Oct 10 '24 21:10 apps-auth

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

apps-auth avatar Oct 13 '24 01:10 apps-auth

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?

ghost avatar Oct 13 '24 22:10 ghost

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.

ethanblake4 avatar Nov 06 '24 06:11 ethanblake4

No longer needed, null access from map was fixed correctly in v0.8.0.

ethanblake4 avatar Jul 20 '25 02:07 ethanblake4