0

I'm trying to assign null to a specific key in Map<String, dynamic> in order to nullify the value in my SQL DB. But I keep getting an error Error: Expected a value of type 'Object', but got one of type 'Null', in dartpad it works fine without any errors.

Here is the error I'm getting:
Error: Expected a value of type 'Object', but got one of type 'Null'
Here is my code:
Map<String, dynamic> map = {};

map["key2"] = null;
Flutter doctor:
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1014, on macOS 12.5.1 21G83 darwin-x64, locale en-IL)
    • Flutter version 3.1.0-0.0.pre.1014 at /Users/daniel/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 08e61c3be2 (6 months ago), 2022-05-31 00:18:09 -0400
    • Engine revision 693f95391e
    • Dart version 2.18.0 (build 2.18.0-152.0.dev)
    • DevTools version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/daniel/Library/Android/sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 12.5.1 21G83 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
  • If you try the above code on dartpad, it doesn't throw anything. – esentis Nov 12 '22 at 10:43
  • Yes, it works for me too, but in Flutter, it still throws an error. I will add flutter doctor to my question. – danielR2001 Nov 12 '22 at 11:40
  • Where in your code are you doing this? Looks like it doesn't work at top level. See https://stackoverflow.com/questions/53908405/how-to-add-a-new-pair-to-map-in-dart – GrahamD Nov 12 '22 at 17:04
  • I found the cause of the problem, I was passing a dynamic parameter (i checked if the type is Map) to a function and was trying to change the passed parameter. Thanks for your help! – danielR2001 Nov 14 '22 at 09:48

0 Answers0