load method
Reads the library from the store. The first time a user allowed to manage it opens it, the defaults of options are stored once.
Implementation
Future<void> load(BuildContext context, {bool force = false}) async {
if (_loading || (_loaded && !force)) return;
_loading = true;
_error = null;
notifyListeners();
// Built before the first await, while the context is surely valid.
final templates =
options.defaultTemplates?.call(context) ?? const <PrintTemplate>[];
final categories =
options.defaultCategories?.call(context) ?? const <PrintCategory>[];
final paperFormats = options.loadDefaultPaperFormats
? PaperFormatDefaults.all(context.reportL10n)
: const <PaperFormat>[];
try {
var library = await store.load();
if (!library.defaultsLoaded && library.canManage) {
library = await store.loadDefaults(
templates: templates.map((item) => item.toItem()).toList(),
paperFormats: paperFormats.map((item) => item.toItem()).toList(),
categories: categories.map((item) => item.toItem()).toList(),
);
}
_apply(library);
_loaded = true;
} catch (error, stack) {
debugPrint('Print library not loaded: $error\n$stack');
_error = error;
} finally {
_loading = false;
notifyListeners();
}
}