我刚接触Flutter开发。我刚开始使用Provider模式制作笔记应用程序,但是当我更新笔记时,它不会更新,而是在列表中创建一个新的笔记。但是当我最小化并返回时,列表已经更新。当我点击项目时,它显示旧数据。请帮助我。
sqlite_helper.dart
import 'package:sqflite/sqflite.dart' as sql;
import 'package:path/path.dart' as path;
import 'package:sqflite/sqlite_api.dart';
class DBHelper {
static Future<Database> database() async {
final dbPath = await sql.getDatabasesPath();
return sql.openDatabase(path.join(dbPath, 'mydatabase.db'),
onCreate: (db, version) {
return db.execute(
'CREATE TABLE notes(id TEXT PRIMARY KEY, title TEXT, content TEXT)');
}, version: 1);
}
static Future<void> insert(String table, Map<String, Object> data) async {
final db = await DBHelper.database();
db.insert(
table,
data,
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
}