-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong context in SailorRoute builder to get BlocProvider #18
Comments
Re-open, closed by accident... |
@zash80 Can you let me know where are you |
@gurleensethi , see here: https://github.com/zash80/flutter-bloc-library-v1-tutorial/blob/master/lib/main.dart - WeatherBloc is set up through BlocProvider as 'home' in MaterialApp. |
Hi @zash80 I took a quick look and the problem is the SailorRoute(
name: '/details',
builder: (context, args, params) {
print('context... $context'); // this context is already the new route context
return BlocProvider.value(
value: BlocProvider.of<WeatherBloc>(context),
child: WeatherDetailPage(
masterWeather: params.param('masterWeather'),
),
);
},
params: [
SailorParam<Weather>(
name: 'masterWeather',
),
],
), I believe in order to fix this you would need to modify Hope that helps 👍 |
To avoid such weird things, I do not Use provider inside router definition, rather I'm using args to pass the data to the page so in the end the definition look slike this
where args are
and the navigation call looks like this
|
I am experiencing a similar issue when trying to instantiate a new Bloc in a Here is a snippet of the relevant ...
SailorRoute(
name: myPage,
builder: (BuildContext context, BaseArguments args, _) {
print('DEBUG_1: creating BlocProvider for MyBloc');
return BlocProvider<MyBloc>(
create: (_) {
print('DEBUG_2: creating MyBloc');
return MyBloc();
},
child: MyPage(),
);
}),
... When the route is pushed, the DEBUG_1 message is printed and the DEBUG_2 message is not, indicating that the With this snippet, in Ideally, the Is there any other idiomatic approach to inject a Bloc using |
@sterrenburg have you tried setting ...
SailorRoute(
name: myPage,
builder: (BuildContext context, BaseArguments args, _) {
print('DEBUG_1: creating BlocProvider for MyBloc');
return BlocProvider<MyBloc>(
lazy: false,
create: (_) {
print('DEBUG_2: creating MyBloc');
return MyBloc();
},
child: MyPage(),
);
}),
... |
Thank you! Adding |
I'm trying to use Sailor with flutter_bloc. When adding a SailorRoute like this:
Seeing following exception:
For details see https://github.com/zash80/flutter-bloc-library-v1-tutorial forked from https://github.com/ResoCoder/flutter-bloc-library-v1-tutorial replacing flutter navigation with Sailor navigation.
The text was updated successfully, but these errors were encountered: