Hello Guys I am working on a flutter project Where I am trying to save data in a sqflite database. Since I am new to flutter so I didn't understand where I am doing it wrong or what is the mistake I made.
The error I am getting is
I/flutter (28200): *** WARNING ***
I/flutter (28200):
I/flutter (28200): Invalid argument {recipeName: Butter Chicken, recipeCategory: Indian Cuisine} with type _InternalLinkedHashMap<String, dynamic>.
I/flutter (28200): Only num, String and Uint8List are supported. See https://github.com/tekartik/sqflite/blob/master/sqflite/doc/supported_types.md for details
I/flutter (28200):
I/flutter (28200): This will throw an exception in the future. For now it is displayed once per type.
I/flutter (28200):
I/flutter (28200):
E/SQLiteLog(28200): (1) near "101": syntax error in "INSERT INTO recipeTable (101, 102, 103, 104, 105, 106, 107, 109, 110) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
E/flutter (28200): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: DatabaseException(near "101": syntax error (code 1 SQLITE_ERROR): , while compiling: INSERT INTO recipeTable (101, 102, 103, 104, 105, 106, 107, 109, 110) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)) sql 'INSERT INTO recipeTable (101, 102, 103, 104, 105, 106, 107, 109, 110) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' args [{recipeName: Butter Chicken, recipeCategory: India..., {recipeName: Tikka, recipeCategory: Indian Cuisine..., {recipeName: Pizza, recipeCategory: Italian Cuisin..., {recipeName: Burger, recipeCategory: Fast Food}, {recipeName: Karai, recipeCategory: Pakistani Cuis..., {recipeName: Handi, recipeCategory: Indian Cuisine..., {recipeName: Soup, recipeCategory: Starter}, {recipeName: Shawarma, recipeCategory: Eastern Cui..., {recipeName: French Fires, recipeCategory: Fast Fo...]
E/flutter (28200): #0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11:7)
E/flutter (28200): <asynchronous suspension>
E/flutter (28200): #1 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure> (package:sqflite_common/src/database_mixin.dart:548:14)
E/flutter (28200): <asynchronous suspension>
E/flutter (28200): #2 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter (28200): <asynchronous suspension>
E/flutter (28200): #3 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:489:14)
E/flutter (28200): <asynchronous suspension>
E/flutter (28200): #4 DatabaseHelper.saveRecipe (package:recipedia/Database/databaseHelper.dart:46:15)
E/flutter (28200): <asynchronous suspension>
E/flutter (28200):
Here is my code Getting data from firestore database and saving it into local database (sqflite)
Future<void> getRecipeData() async {
recipes = await RecipeModel().getRecipeDataList();
count = await RecipeModel().getRecipeCount();
//Converting List into Map
for (int i=0; i<count;i++) {
recipeMap[recipes[i].recipeID] = {
'recipeName': recipes[i].recipeName,
'recipeCategory': recipes[i].recipeCategory,
};
}
//Storing data into database
DatabaseHelper().saveRecipe(recipeMap);
}
This is my database class
class DatabaseHelper {
static final DatabaseHelper _instance = DatabaseHelper.internal();
factory DatabaseHelper() => _instance;
final String recipeTable = 'recipeTable';
final String recipeId = 'recipeId';
final String recipeName = 'recipeName';
final String recipeCategory = 'recipe_category';
final String columnSynced = 'synced';
static Database? _db;
Future<Database?> get db async {
if (_db != null) {
return _db;
}
_db = await initDb();
return _db;
}
DatabaseHelper.internal();
initDb() async {
String databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'recipe.db');
var db = await openDatabase(path, version: 1, onCreate: _onCreate);
return db;
}
void _onCreate(Database db, int newVersion) async {
await db.execute(
'CREATE TABLE $recipeTable($recipeId INTEGER PRIMARY KEY, $recipeName TEXT, $recipeCategory TEXT, $columnSynced INTEGER)');
}
Future<int> saveRecipe(Map<String, dynamic> recipe) async {
var dbClient = await db;
int res = await dbClient!.insert(recipeTable, recipe);
return res;
}
}
Please help me to resolve the issue. All the efforts in question will be appreciated. Thankyou