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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With