我使用 Flutter 的 SQFlite 插件创建了一个应用程序。在 iOS 和大多数 Android 手机上一切正常,但我有一位测试人员在他的 OnePlus 设备上遇到了一些非常奇怪的行为,特别是运行 OxygenOS 9.0.1 的 OnePlus 5)。显然,卸载应用程序后数据库仍然存在(会加载旧数据),然后它“有时会保存,有时不会”。
以下是我用来创建数据库的代码:
_initDatabase() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, _databaseName);
return await openDatabase(path,
version: _databaseVersion, onCreate: _onCreate);
}
这是 _onCreate() 方法:
Future _onCreate(Database db, int version) async {
await db.transaction((txn) async {
await txn.execute('''
CREATE TABLE $tableCharacters (
$columnCharacterId INTEGER PRIMARY KEY,
$columnCharacterName TEXT NOT NULL
)''');
await txn.execute('''
CREATE TABLE $tablePerks (
$columnPerkId INTEGER PRIMARY KEY,
$columnPerkClass TEXT NOT NULL,
$columnPerkDetails TEXT NOT NULL
)''').then((_) async {
for (Perk perk in perkList) {
for (int i = 0; i < perk.numOfPerks; i++) {
int id = await txn.insert(tablePerks, perk.toMap());
print("ID: " +
id.toString() +
" : " +
perk.perkClassCode +
" : " +
perk.perkDetails);
}
}
});
await txn.execute('''
CREATE TABLE $tableCharacterPerks (
$columnAssociatedCharacterId INTEGER,
$columnAssociatedPerkId INTEGER,
$columnCharacterPerkIsSelected BOOLEAN
)''');
});
}
我的问题是:这种方法有什么问题可以解决我的 OnePlus 设备问题吗?我能做些什么来确保它能够正确安装在这些手机上吗?我有超过 6k 的活跃用户,所以我绝对希望这个版本保持密封。
谢谢你。