Want to make a Sink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import 'dart:async'; // Sink, Stream import 'dart:ui'; // Locale import 'package:rxdart/rxdart.dart'; // Observable, *Subject class Bloc { var _locale = BehaviorSubject<Locale>(seedValue: Locale('en', 'US')); var _items = BehaviorSubject<List<CartItem>>(seedValue: []); Stream<String> _totalCost; Sink<Locale> get locale => _locale.sink; Stream<List<CartItem>> get items => _items.stream; Stream<String> get totalCost => _totalCost; Bloc() { _totalCost = Observable.combineLatest2<Locale, List<CartItem>, String>( _locale, _items, (locale, items) { // TODO calculate total price of items and format based on locale return 'USD 10.00'; }).asBroadcastStream(); } void dispose() { _locale.close(); _items.close(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.