Hello, I got unexpected behavior with bloc where I want to navigate to Filter page when user taps on Sort and pass productsbloc to it
here is sample code:
```import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.only(top: 58.0),
child: GestureDetector(
onTap: () {
BlocProvider
create: (context) => ProductsBloc(),
child: Filter(),
);
},
child: Center(child: Icon(Icons.sort)),
),
),
);
}
}
class Filter extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('data'),
);
}
}
class ProductsBloc extends Bloc
ProductsBloc() : super(InitialState());
@override
Stream
// TODO: implement mapEventToState
throw UnimplementedError();
}
}
class ProductsEvent {}
class ProductsState {}
class InitialState extends ProductsState {}
```
Hi @EngAddow 馃憢
Thanks for opening an issue!
It doesn't appear you are navigating and it looks like you're just creating a new bloc and Filter widget. I think you should do something like:
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => BlocProvider(create: (_) => ProductsBloc(), child: Filter()),
),
);
}
Closing for now but feel free to comment if you still have questions and I'm happy to continue the conversation 馃憤
Thanks @felangel I appreciated for your time and how you reply quickly and very helpful even when the issue is not yours
Most helpful comment
Hi @EngAddow 馃憢
Thanks for opening an issue!
It doesn't appear you are navigating and it looks like you're just creating a new bloc and Filter widget. I think you should do something like:
Closing for now but feel free to comment if you still have questions and I'm happy to continue the conversation 馃憤