序列化

Flutter调用JSON序列化出现type 'String' is not a subtype of type 'MapString, dynamic'

问题情况

本来按照书上的思路都封装好了Dio,半自动生成了Json Model,结果在实际应用上出现了以下异常:

Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic>'


Flutter生成JSON序列化模板报错

问题详情:

在执行flutter packages pub run build_runner build自动生成JSON序列化模板的时候出现了以下报错:

Generator cannot target libraries that have not been migrated to null-safety.
package:flutter_test2/model/recommender.dart:6:7
  ╷
6 │ class Recommender {
  │       ^^^^^^^^^^^
  ╵
[INFO] Running build completed, took 1.0s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 41ms
[SEVERE] Failed after 1.1s
pub finished with exit code 1