This could be a silly question but I don't get how should I pass a parameter to DI class in flutter (dart) with GetIt.

Sample:

@injectable
class Bloc
    extends Bloc<Event, State> { 

  Bloc(@factoryParam String url)
      : super(const ShowHideColumnBullListState.initial());
//more code
}

Snippet with creating/retrieving Bloc:

Widget _buildBlocProviderWidget(BuildContext context) {
    const event = Event.didStart();
    return BlocProvider(
      create: (context) => getIt<Bloc>()..add(event),//what should I call to pass String as a parameter? I cannot pass String to constructor call ()
      child: _buildBlocConsumerWidget(context),
    );
  }


Solution 1: yellowgray

I think you are looking for this:

getIt<Bloc>(param1: url,);

from get_it (Passing Parameters to factories)

/// registers a type so that a new instance will be created on each call of [getAsync]
/// on that type based on up to two parameters provided to [getAsync()]
/// the creation function is executed asynchronously and has to be accessed  with [getAsync]
/// [T] type to register
/// [P1] type of  param1
/// [P2] type of  param2
/// if you use only one parameter pass void here
/// [func] factory function for this type that accepts two parameters
/// [instanceName] if you provide a value here your factory gets registered with that
/// name instead of a type. This should only be necessary if you need to register more
/// than one instance of one type. Its highly not recommended
///
/// example:
///    getIt.registerFactoryParam<TestClassParam,String,int>((s,i) async
///        => TestClassParam(param1:s, param2: i));
///
/// if you only use one parameter:
///
///    getIt.registerFactoryParam<TestClassParam,String,void>((s,_) async
///        => TestClassParam(param1:s);
@override
void registerFactoryParamAsync<T, P1, P2>(
    FactoryFuncParamAsync<T, P1, P2> func,
    {String instanceName}) {
  _register<T, P1, P2>(
      type: _ServiceFactoryType.alwaysNew,
      instanceName: instanceName,
      factoryFuncParamAsync: func,
      isAsync: true,
      shouldSignalReady: false);
}