internalZcodeDBInit function

void internalZcodeDBInit({
  1. String? dbUrl,
  2. String? sqlite3Url,
})

init zcode word database for platform other than web. dbUrl and sqlite3Url will not need to set. They are for web platform.

Implementation

void internalZcodeDBInit({String? dbUrl, String? sqlite3Url}) async {
  if (zcodeDB == null) {
    final documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, "zcode_ime.db");
    if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound) {
      ByteData data =
          await rootBundle.load('packages/zcode_embed_ime_db/db/zcode_ime.db');
      final bytes =
          data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
      await File(path).writeAsBytes(bytes);
    }
    zcodeDB = sqlite3.open(path);
  }
}