Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pass a parameter known only at run time to an object created by getit dependency injection?

Is there a way to pass a parameter known only at run time to an object created by getit dependency injection when the object is being created or retrieved from a Dependency Injector?

class WatchVideoPage extends StatelessWidget {
  Widget build(BuildContext context) {
    return BlocProvider(
      create: () => locator<WatchVideoPageBloc>(), // I want the bloc to know of the videoId.
      child: new RandomWidget()
    );
  }

  final VideoId videoId;
}

'locator' is the dependency injection thing in the code.

Or is there another way of making the bloc know the value of videoId?

Thanks!

like image 332
Yamin Nather Avatar asked Nov 23 '25 11:11

Yamin Nather


1 Answers

You can just create an event that makes the video ID known to the bloc:

create: () => locator<WatchVideoPageBloc>()..add(StartStreaming(videoId)),

Obviously, that means you need an event called StartStreaming that takes a VideoId in their constructor.

like image 159
nvoigt Avatar answered Nov 28 '25 02:11

nvoigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!