Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation pour Windows - La base de données n'est pas recopiée en userPath/Documents ci joint le correctif #3521

Open
alain-bossa opened this issue Feb 2, 2024 · 0 comments

Comments

@alain-bossa
Copy link

Le fichier qui corrige le problème de non recopie du fichier bible.db est le suivant :
bibleDbProvider.dart
import 'dart:io';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

class BibleDbSqfProvider {
static final _databaseName = "bible.db";

// make this a singleton class
BibleDbSqfProvider._privateConstructor();
static final BibleDbSqfProvider instance = BibleDbSqfProvider._privateConstructor();

Database? db;

Future ensureDatabase() async {
if (db == null) {
var databasesPath = await getApplicationDocumentsDirectory();
var path = join(databasesPath.path, databaseName);
// Check if the database exists
if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound){
// Should happen only the first time you launch your application
print("Creating new copy from asset");
// Make sure the parent directory exists
try {
await Directory(dirname(path)).create(recursive: true);
} catch (
) {}
// Copy from asset
ByteData data = await rootBundle.load(join("assets/", _databaseName));
List bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
// Write and flush the bytes written
await File(path).writeAsBytes(bytes, flush: true);
} else {}
print('SQLite3.open Bible db');
this.db = await databaseFactory.openDatabase(path);
print('Bible db = ${this.db.hashCode}');
}
}

Database? getDatabase() {
assert(this.db != null);
return db;
}
}

Sur Android et Windows l'IHM n'apparait pas. Le correctif est le suivant :
Dans le fichier main.dart il faut rajouter MaterialApp comme ci après
void main() {
runApp(MaterialApp(
home: MyApp(storage: ChapterStorage('assets/bible/gn1.txt'))));
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;
// Initialize database
ensureDatabase();
}

Cordialement.
Merci pour votre travail sur AELF.

Alain CRESSOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant