mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 10:15:32 +00:00
UserProfile
This commit is contained in:
@ -1,8 +1,57 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'api.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sembast/sembast.dart';
|
||||
import 'package:sembast/sembast_io.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'dart:async';
|
||||
|
||||
|
||||
/*
|
||||
* Class for storing InvenTree preferences in a NoSql DB
|
||||
*/
|
||||
class InvenTreePreferencesDB {
|
||||
|
||||
static final InvenTreePreferencesDB _singleton = InvenTreePreferencesDB._();
|
||||
|
||||
static InvenTreePreferencesDB get instance => _singleton;
|
||||
|
||||
InvenTreePreferencesDB._();
|
||||
|
||||
Completer<Database> _dbOpenCompleter;
|
||||
|
||||
Future<Database> get database async {
|
||||
// If completer is null, AppDatabaseClass is newly instantiated, so database is not yet opened
|
||||
if (_dbOpenCompleter == null) {
|
||||
_dbOpenCompleter = Completer();
|
||||
// Calling _openDatabase will also complete the completer with database instance
|
||||
_openDatabase();
|
||||
}
|
||||
// If the database is already opened, awaiting the future will happen instantly.
|
||||
// Otherwise, awaiting the returned future will take some time - until complete() is called
|
||||
// on the Completer in _openDatabase() below.
|
||||
return _dbOpenCompleter.future;
|
||||
}
|
||||
|
||||
Future _openDatabase() async {
|
||||
// Get a platform-specific directory where persistent app data can be stored
|
||||
final appDocumentDir = await getApplicationDocumentsDirectory();
|
||||
|
||||
print("Documents Dir: ${appDocumentDir.toString()}");
|
||||
|
||||
print("Path: ${appDocumentDir.path}");
|
||||
|
||||
// Path with the form: /platform-specific-directory/demo.db
|
||||
final dbPath = join(appDocumentDir.path, 'InvenTreeSettings.db');
|
||||
|
||||
final database = await databaseFactoryIo.openDatabase(dbPath);
|
||||
|
||||
// Any code awaiting the Completer's future will now start executing
|
||||
_dbOpenCompleter.complete(database);
|
||||
}
|
||||
}
|
||||
|
||||
class InvenTreePreferences {
|
||||
|
||||
static const String _SERVER = 'server';
|
||||
|
Reference in New Issue
Block a user