mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-26 20:50:18 +08:00

Deleted files: * `sample_eco_knowledge_panels.json`: replaced by new file `sample_knowledge_panels.json` * `sample_health_knowledge_panels.json`: replaced by new file `sample_knowledge_panels.json` New files: * `abstract_onboarding_data.dart`: Abstraction of data we download, store and reuse at onboarding. * `dao_string.dart`: Where we store strings. * `loading_dialog.dart`: Dialog with a stop button, while a future is running. * `onboarding_data_knowledge_panels.dart`: Helper around knowledge panels we download, store and reuse at onboarding. * `onboarding_data_product.dart`: Helper around a product we download, store and reuse at onboarding. * `onboarding_loader.dart`: Helper around data we download, store and reuse at onboarding. * `sample_knowledge_panels.json`: json data downloaded today for en_US, cf. onboarding_data_knowledge_panels.dart * `tmp.dart`: Fixes to off-dart. Impacted files: * `knowledge_panel_page_template.dart`: added parameters to 1. use the database (and downloaded data) and 2. limit the display to a given panel * `knowlegde_panel_builder.dart`: added a method to display only one panel * `local_database.dart`: added new dao `DaoString` * `new_product_page.dart`: refactored * `next_button.dart`: added an optional call to async methods at "next" time - e.g. data download * `nutrition_page_loaded.dart`: now uses the new `LoadingDialog` * `onboarding_flow_navigator.dart`: now using the database to get more relevant (previoulsy downloaded) data * `preferences_page.dart`: now using previously downloaded data instead of assets * `product_dialog_helper.dart`: now uses the new `LoadingDialog` * `question_card.dart`: unrelated minor refactoring * `sample_eco_card_page.dart`: now using previously downloaded data instead of assets, and displaying only the environment card * `sample_health_card_page.dart`: now using previously downloaded data instead of assets, and displaying only the health card * `sample_product_json.dart`: json data downloaded today for en_US, cf. onboarding_data_product.dart * `sign_up_page.dart`: now uses the new `LoadingDialog`
41 lines
1.3 KiB
Dart
41 lines
1.3 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_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';
|
|
|
|
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),
|
|
];
|
|
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;
|
|
}
|