Files
monsieurtanuki 954449e437 feat: #935 - now we display localized (downloaded) data during onboarding (#986)
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`
2022-01-20 20:28:07 +01:00

29 lines
1019 B
Dart

import 'package:hive_flutter/hive_flutter.dart';
import 'package:smooth_app/database/abstract_dao.dart';
import 'package:smooth_app/database/local_database.dart';
/// Where we store strings.
///
/// Typical use case: large strings used for onboarding.
/// That's why we use lazy boxes, and not boxes, and not sharedpreferences:
/// we're talking about large data (several 10Kb) that we almost never need,
/// and that should not make the app boot slower.
class DaoString extends AbstractDao {
DaoString(final LocalDatabase localDatabase) : super(localDatabase);
static const String _hiveBoxName = 'string';
@override
Future<void> init() async => Hive.openLazyBox<String>(_hiveBoxName);
@override
void registerAdapter() {}
LazyBox<String> _getBox() => Hive.lazyBox<String>(_hiveBoxName);
Future<String?> get(final String key) async => _getBox().get(key);
Future<void> put(final String key, final String? value) async =>
value == null ? _getBox().delete(key) : _getBox().put(key, value);
}