gpt4 book ai didi

android - Flutter - SQflite '_InternalLinkedHashMap' 不是类型 'Map' 的子类型

转载 作者:IT王子 更新时间:2023-10-29 06:43:57 26 4
gpt4 key购买 nike

我正在尝试在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com