1
flutter
protocol_error
ai_generated
true
PlatformException: error: 1, message: Invalid argument, details: Expected a Map but got List
ID: flutter/platform-channel-argument-error
85%Fix Rate
88%Confidence
1Evidence
2024-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Flutter 3.22.0 | active | — | — | — |
| Dart 3.4.0 | active | — | — | — |
| Kotlin 1.9.22 | active | — | — | — |
| Swift 5.9 | active | — | — | — |
Root Cause
Platform channel method call arguments are not a valid Map, often due to incorrect encoding on the native side.
generic中文
平台通道方法调用参数不是有效的 Map,通常是由于原生端编码错误。
Official Documentation
https://docs.flutter.dev/platform-integration/platform-channelsWorkarounds
-
90% success In the native Android handler, ensure arguments are wrapped in a HashMap. Example: `result.success(mapOf("key" to value))` instead of `result.success(listOf(...))`.
In the native Android handler, ensure arguments are wrapped in a HashMap. Example: `result.success(mapOf("key" to value))` instead of `result.success(listOf(...))`. -
85% success On iOS, use a dictionary: `result(["key": value])` and verify the Flutter side expects a Map. Also check for nil values in the dictionary.
On iOS, use a dictionary: `result(["key": value])` and verify the Flutter side expects a Map. Also check for nil values in the dictionary.
-
75% success Add a try-catch on the native side to log the exact argument type: `try { ... } catch (e) { Log.e("Channel", "Argument type: ${arg.runtimeType}"); }`.
Add a try-catch on the native side to log the exact argument type: `try { ... } catch (e) { Log.e("Channel", "Argument type: ${arg.runtimeType}"); }`.
中文步骤
In the native Android handler, ensure arguments are wrapped in a HashMap. Example: `result.success(mapOf("key" to value))` instead of `result.success(listOf(...))`.On iOS, use a dictionary: `result(["key": value])` and verify the Flutter side expects a Map. Also check for nil values in the dictionary.
Add a try-catch on the native side to log the exact argument type: `try { ... } catch (e) { Log.e("Channel", "Argument type: ${arg.runtimeType}"); }`.
Dead Ends
Common approaches that don't work:
-
95% fail
The root cause is in the native method channel implementation, not a transient state issue.
-
90% fail
The error is raised on the native side before Dart receives the response; null checks don't fix encoding.
-
80% fail
The error is specific to custom method channel code, not package compatibility.