这是我存储在数据库中的数据
[{count:3,minced:0,category_id:3,size_id:63,chops_id:null,cookie_id:null,choole:null,notes:},{count:4,minced:0,category_id:3,size_id:62 ,chops_id:null,cookie_id:null,choole:null,notes:},{count:2,minced:2,category_id:2,size_id:49,chops_id:8,cookie_id:8,choole:2,notes:bzbznzjz} ]
以及我需要发送给 API 的内容
[{"size_id":59,"count":2,"category_id":2,"chops_id":null,"cookie_id":null,"choole":null,"notes":"jgg","minced": 0},{"size_id":63,"count":3,"category_id" :2,"chops_id":4,"cookie_id":8,"choole":2,"notes":"tvv","minced “:1}]
我需要将此“”添加到我的密钥中,我该怎么做?这就是我的代码
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'Models/product.dart';
class DatabaseHelper {
Product _product;
static final DatabaseHelper _instance = new DatabaseHelper.internal();
factory DatabaseHelper() => _instance;
static Database _db;
Future<Database> get db async {
if (_db != null) return _db;
_db = await initDb();
return _db;
}
DatabaseHelper.internal();
initDb() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "main.db");
var theDb = await openDatabase(path, version: 1, onCreate: _onCreate);
return theDb;
}
void _onCreate(Database db, int version) async {
await db.execute(
"CREATE TABLE Product(id INTEGER PRIMARY KEY, count INTEGER, minced INTEGER, rate DOUBLE, category_id INTEGER, size_id INTEGER, chops_id INTEGER, cookie_id INTEGER, choole INTEGER, notes TEXT, name TEXT, image TEXT, size_name TEXT, category_name TEXT)"); }
Future<int> saveProduct(Product product) async {
var dbProduct = await db;
int res = await dbProduct.insert("Product", product.toMap());
print(product.toMap());
return res;
}
Future<List> getAllProduct() async {
var dbProduct = await db;
var result = await dbProduct.rawQuery("SELECT * FROM Product");
return result.toList();
}
Future<List> getCartProduct() async {
var dbProduct = await db;
var result = await dbProduct.rawQuery("SELECT count, minced, category_id, size_id, chops_id, cookie_id, choole, notes FROM Product");
return result;
}
Future<int> getCount() async {
var dbProduct = await db;
return Sqflite.firstIntValue(
await dbProduct.rawQuery("SELECT COUNT(*) FROM Product"));
}
Future<Product> getProduct(int id) async {
var dbProduct = await db;
var result = await dbProduct.rawQuery("SELECT * FROM Product WHERE id = $id");
if (result.length == 0) return null;
return new Product.fromMap(result.first);
}
Future<int> deleteProducts(Product product) async {
var dbProduct = await db;
int res = await dbProduct
.rawDelete('DELETE FROM Product WHERE id = ?', [product.id]);
return res;
}
update(Product product) async {
var dbProduct = await db;
int res = await dbProduct.update("Product", product.toMap(),
where: "id = ?", whereArgs: <int>[product.id]);
return res > 0 ? true : false;
}
}