写入文件时,它在writeAsbytes上引发异常:无法打开文件。它适用于android API 22以上版本,但不适用于android API 22 Samsung设备上。
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, DB_NAME);
if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound) {
// Load database from asset and copy
ByteData data = await rootBundle.load(join('assets', DB_NAME));
List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
// Save copied asset to documents
await new File(path).writeAsBytes(bytes,flush: true);
}
_database = await openDatabase(
path,
);
} catch (e) {
e.toString();
}