Convert ByteData before writing into file (#1555)

ByteData can not be written directly into file using writeAsBytes method.
It must be converted to Uint8List before the operation.
This commit is contained in:
Munjata KEITA 2021-11-21 22:24:32 +00:00 committed by GitHub
parent 214fbe2409
commit 1eb36eaaea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -45,7 +45,8 @@ LazyDatabase _openConnection() {
if (!await file.exists()) { if (!await file.exists()) {
// Extract the pre-populated database file from assets // Extract the pre-populated database file from assets
final blob = await rootBundle.load('assets/my_database.db'); final blob = await rootBundle.load('assets/my_database.db');
await file.writeAsBytes(blob); final buffer = blob.buffer;
await file.writeAsBytes(buffer.asUint8List(blob.offsetInBytes, blob.lengthInBytes));
} }
return NativeDatabase(file); return NativeDatabase(file);
@ -61,4 +62,4 @@ class MyDatabase extends _$MyDatabase {
MyDatabase() : super(_openConnection()); MyDatabase() : super(_openConnection());
// ... // ...
``` ```