Files
smooth-app/packages/smooth_app/lib/database/local_database.dart
cli1005 f67180785d fix: #1352 - robotoff insight card shows permanently (#1574)
* fix: #1395 - show newly added product in carousel

* fix: #1395 - refactoring unused import

* fix: #1395 - refactoring make variable private

* fix: #1352 - robotoff card shows permanently

* fix: #1352 - codereview refactoring

* fix: #1352 - check fix

* fix: #1352 - pretest check fix

* fix: #1352 - codereview fix

Co-authored-by: Pierre Slamich <pierre@openfoodfacts.org>
2022-04-21 10:58:52 +02:00

45 lines
1.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:smooth_app/database/abstract_dao.dart';
import 'package:smooth_app/database/dao_int.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/dao_string.dart';
import 'package:smooth_app/database/dao_string_list.dart';
import 'package:smooth_app/database/dao_string_list_map.dart';
class LocalDatabase extends ChangeNotifier {
LocalDatabase._();
/// Notify listeners
/// Comments added only in order to avoid a "warning"
/// For the record, we need to override the method
/// because the parent's is protected
@override
void notifyListeners() => super.notifyListeners();
static Future<LocalDatabase> getLocalDatabase() async {
await Hive.initFlutter();
final LocalDatabase localDatabase = LocalDatabase._();
final List<AbstractDao> daos = <AbstractDao>[
DaoProduct(localDatabase),
DaoProductList(localDatabase),
DaoStringList(localDatabase),
DaoString(localDatabase),
DaoInt(localDatabase),
DaoStringListMap(localDatabase),
];
for (final AbstractDao dao in daos) {
dao.registerAdapter();
}
for (final AbstractDao dao in daos) {
await dao.init();
}
return localDatabase;
}
static int nowInMillis() => DateTime.now().millisecondsSinceEpoch;
}