ensureProfileLoaded static method
ensureProfileLoaded this method will cache the profile json into data which will speed up the next loop and searching profile
Implementation
static Future ensureProfileLoaded({String? path}) async {
/// check where this global capabilities is empty then load capabilities.json
/// else do nothing
if (printCapabilities.isEmpty == true) {
final content = await rootBundle.loadString(
path ?? 'packages/esc_pos_utils_plus/resources/capabilities.json');
var _capabilities = json.decode(content);
printCapabilities = Map.from(_capabilities);
_capabilities['profiles'].forEach((k, v) {
printProfiles.add({
'key': k,
'vendor': v['vendor'] is String ? v['vendor'] : '',
'name': v['name'] is String ? v['name'] : '',
'description': v['description'] is String ? v['description'] : '',
});
});
/// assert that the capabilities will be not empty
assert(printCapabilities.isNotEmpty);
} else {
print("capabilities.length is already loaded");
}
}