Last active
April 3, 2020 07:01
-
-
Save GIfatahTH/8c56ddb9321659f40218c04751dfa1f5 to your computer and use it in GitHub Desktop.
MainBloc class of Bloc Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainBloc { | |
final itemProvider = ItemProvider(); | |
final itemsConroller = StreamController<List<Item>>(); | |
final detailedColorConroller = StreamController<Color>(); | |
final detailedItemConroller = StreamController<Item>(); | |
Stream get itemsStream => itemsConroller.stream; | |
Stream get detailedColorStream => detailedColorConroller.stream; | |
Stream get detailedItemStream => detailedItemConroller.stream; | |
StreamSink<List<Item>> get itemsSink => itemsConroller.sink; | |
StreamSink<Color> get detailedColorSink => detailedColorConroller.sink; | |
StreamSink<Item> get detailedItemSink => detailedItemConroller.sink; | |
List<Item> _items; | |
int _detailedIndex; | |
getItems() async { | |
_items = await itemProvider.fetchItems(); | |
itemsSink.add(_items); | |
} | |
showDetailed(Color color, int index, Item item) { | |
detailedColorSink.add(color); | |
detailedItemSink.add(item); | |
_detailedIndex = index; | |
} | |
increment() { | |
_items[_detailedIndex].count++; | |
itemsSink.add(_items); | |
detailedItemSink.add(_items[_detailedIndex]); | |
} | |
void dispose() { | |
itemsConroller.close(); | |
detailedColorConroller.close(); | |
detailedItemConroller.close(); | |
} | |
} | |
MainBloc mainBloc = MainBloc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have u got a full example of app?