initialize method

  1. @override
Future<void> initialize(
  1. BuildContext context, {
  2. IFastErrorReporter? errorReporter,
})
override

Initializes the job to retrieve country data.

This method starts the job to retrieve and process country-specific metadata. It will fetch the data using the provided delegate, and then update the associated BLoC's state.

Implementation

@override
Future<void> initialize(
  BuildContext context, {
  IFastErrorReporter? errorReporter,
}) async {
  final bloc = MatexCountryBloc.instance;
  String? jsonData;

  if (delegate != null) {
    jsonData = await delegate!.onGetCountryJsonMetadata(context);
  }

  bloc.addEvent(MatexCountryBlocEvent.init(jsonData: jsonData));

  final blocState = await RaceStream([
    bloc.onError,
    bloc.onData.where((state) => state.isInitialized),
  ]).first;

  if (blocState is! MatexCountryBlocState) {
    throw blocState;
  }
}