35 lines
691 B
Dart
35 lines
691 B
Dart
|
|
import 'dart:async';
|
||
|
|
|
||
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
||
|
|
import 'package:rxdart/rxdart.dart';
|
||
|
|
|
||
|
|
class PackHolder {
|
||
|
|
final StreamController<PackState?> _streamController =
|
||
|
|
StreamController.broadcast();
|
||
|
|
PackState? _state;
|
||
|
|
|
||
|
|
PackHolder();
|
||
|
|
|
||
|
|
void setPacks(List<CardPackDto> packs) {
|
||
|
|
_state = PackState(
|
||
|
|
packs,
|
||
|
|
);
|
||
|
|
_streamController.add(_state);
|
||
|
|
}
|
||
|
|
|
||
|
|
void clear() {
|
||
|
|
_state = null;
|
||
|
|
_streamController.add(_state);
|
||
|
|
}
|
||
|
|
|
||
|
|
PackState? get state => _state;
|
||
|
|
|
||
|
|
Stream<PackState?> get asStream => _streamController.stream.startWith(_state);
|
||
|
|
}
|
||
|
|
|
||
|
|
class PackState {
|
||
|
|
final List<CardPackDto> packsWithCards;
|
||
|
|
|
||
|
|
PackState(this.packsWithCards);
|
||
|
|
}
|