Reputation: 568
I had Bloc class before using BlocProvider as below.
And I want to use blockProvider using 'flutter_bloc 4.0.0'.
class SelfRentalBloc {
final _srsController = StreamController<List<SelfRental>>.broadcast();
get srs => _srsController.stream;
SelfRentalBloc() {
getSRs();
}
... more code
}
So I added blocProvider in myApp.dart. void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (BuildContext context) => SelfRentalBloc(),
child: MaterialApp(
initialRoute: '/',
routes: {
'/': (BuildContext context) => HomePage(),
'/page': (BuildContext context) => Page(),
},
));
}
}
But It says SelfRental doesn't extend Bloc.
I think I have to modify SelfRentalBloc class above.
But I don't know how to make it. Could you recommend some solution? Thank you for reading it.
I've already read documentation of flutter_bloc. but it 's too hard to understand for my case due to my low level flutter.
Upvotes: 5
Views: 14233
Reputation: 11
'flutter_bloc 4.0.0' is build to use block (or extended bloc) from the library itself.
In the documentation you can find an exemple of how you can implement you're own bloc : https://pub.dev/packages/flutter_bloc#-example-tab-
You can see this class signature in the example:
class CounterBloc extends Bloc<CounterEvent, int>
The Event is an event identification of which bloc action you want to trigger. The value is same type of the 'state' of your bloc.
To use the library try the example but I think you need to rewrite your bloc to be compliant with the library or keep your custom implementation.
Upvotes: 1