android - Flutter - SQflite '_InternalLinkedHashMap<dynamic, dynamic>' 不是类型 'Map<String, dynamic>' 的子类型

标签 android ios dart flutter

我正在尝试在 sqflite 数据库中保存一些带有 flutter 的数据,但我仍然收到一条错误消息:

[ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled
exception:
    type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>'

错误说错误在这个函数内部:

Future<RecipesDB> insertRecipe(RecipesDB recipe) async{
    var count = Sqflite.firstIntValue(await _db.rawQuery("SELECT COUNT(*) FROM recipes WHERE name = ?", [recipe.name]));
    if(count == 0){
      recipe.id = await _db.insert("recipes", recipe.toMap()); //"toMap()" function returns the error;
    } else {
      await _db.update("recipes", recipe.toMap(), where: "id = ?", whereArgs: [recipe.id]);
    }
    return recipe;
  }

而这个 recipe.toMap() 指向我的类:

import 'dart:convert';

class RecipesDB{
  RecipesDB();

  int id, favorite;
  double workDuration;
  String name, definition, timestamp;

  static final columns = ["id", "name", "definition","duration", "favorite", "timestamp"];

  Map toMap(){
    Map map = {
      "name": name,
      "definition": definition,
      "favorite": favorite,
      "duration": workDuration,
      "timestamp": timestamp
    };

    if(id != null){
      map["id"] = id;
    }

    return map;
  }

  static fromMap(Map map){
    RecipesDB recipes = new RecipesDB();

    recipes.id = map["id"];
    recipes.name = map["name"];
    recipes.definition = map["definition"];
    recipes.workDuration = map["duration"];
    recipes.favorite = map["favorite"];
    recipes.timestamp = map["timestamp"];

    return recipes;
  }

}

我不知道如何解决这个错误。如果你们中有人能救我,那就太好了。

提前致谢 XD!

最佳答案

改变

Map toMap(){
  Map map = {

Map<String,dynamic> toMap(){
  Map<String,dynamic> map = {

关于android - Flutter - SQflite '_InternalLinkedHashMap<dynamic, dynamic>' 不是类型 'Map<String, dynamic>' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52554117/

相关文章:

android - 自定义单选按钮图像未填充空间

android - 计算机未检测到华硕 Zenfone 5

android - 未设置 PlaceSelectionListener。不会传递任何结果

ios - 如何在不创建 CLLocationManager 实例的情况下请求位置授权?

ios - 架构 i386 iOS 的 undefined symbol

flutter - 状态与类变量及其值是否相同?

dart - 如何计算不稳定性和抽象度

android - 无法在android中使用Asynchttpclient将图像上传到服务器

ios - UIAlertController 文本字段宽度比平时小得多

Dart 构造函数初始化顺序