I am trying to save some data with flutter inside the sqflite database, but I am still getting an error that says:
[ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>'
The error says that the error is inside this function:
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;
}
And this recipe.toMap()
points to my class:
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;
}
}
I do not know how to solve this error. It would be great, if somebody of you could save me.
Thanks in advance XD!
change
Map toMap(){
Map map = {
to
Map<String,dynamic> toMap(){
Map<String,dynamic> map = {
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加