diff --git a/lib/bloc/data_loading_bloc/data_loading_bloc.dart b/lib/bloc/data_loading_bloc/data_loading_bloc.dart index fa46dd6..f1167d3 100644 --- a/lib/bloc/data_loading_bloc/data_loading_bloc.dart +++ b/lib/bloc/data_loading_bloc/data_loading_bloc.dart @@ -165,6 +165,7 @@ class DataLoadingBloc extends Bloc { Emitter emit, ) async { emit(LoadingRepositoryState('Importing data')); + print("Importing data from $path"); final json = await File(path).readAsString(); final data = jsonDecode(json); @@ -176,24 +177,26 @@ class DataLoadingBloc extends Bloc { ); final fittings = List.from( data['fittings'].map( - (x) => { + (x) { if (x['type'] == null || x['type'] == 'LOADOUT') { - ShipFittingLoadout.fromJson(x) + return ShipFittingLoadout.fromJson(x); } else if (x['type'] == "FOLDER") { - ShipFittingFolder.fromJson(x) + return ShipFittingFolder.fromJson(x); } else { - //Should never happen - null + //Should not happen unless we try to import data from a newer version + throw Exception('Invalid fitting type ${x['type']}'); } } ), ); + print("Converted json data"); await _characterRepository.loadCharacters( data: characters, defaultPilot: data[CharacterRepository.defaultPilotPrefsKey], ); await _fittingRepository.loadLoadouts(data: fittings); + print("Loaded data"); emit(RepositoryLoadedState()); } diff --git a/lib/model/ship/ship_fitting_loadout.dart b/lib/model/ship/ship_fitting_loadout.dart index 55ee6ff..42d95b5 100644 --- a/lib/model/ship/ship_fitting_loadout.dart +++ b/lib/model/ship/ship_fitting_loadout.dart @@ -90,6 +90,7 @@ class ShipFittingLoadout extends ChangeNotifier json['lightDestroyersSlots'] = json['lightDestroyersSlots'] ?? {}; json['hangarRigSlots'] = json['hangarRigSlots'] ?? {}; + json['type'] = json['type'] ?? 'LOADOUT'; return _$ShipFittingLoadoutFromJson(json); }