mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-12-15 08:19:03 -05:00
statenotifier
This commit is contained in:
parent
8f0b4aaba0
commit
7a49497620
15 changed files with 28 additions and 56 deletions
|
|
@ -1,26 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
// Caches a state value which can be changed from anywhere
|
||||
// Creates a provider interface that notices when the value changes
|
||||
class ExternalStreamState<T> {
|
||||
ExternalStreamState(T initialState)
|
||||
: currentState = initialState,
|
||||
streamController = StreamController<T>.broadcast();
|
||||
T currentState;
|
||||
StreamController<T> streamController;
|
||||
void add(T newState) {
|
||||
currentState = newState;
|
||||
streamController.add(newState);
|
||||
}
|
||||
|
||||
AutoDisposeStreamProvider<T> provider() =>
|
||||
AutoDisposeStreamProvider<T>((ref) async* {
|
||||
if (await streamController.stream.isEmpty) {
|
||||
yield currentState;
|
||||
}
|
||||
await for (final value in streamController.stream) {
|
||||
yield value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
export 'animations.dart';
|
||||
export 'external_stream_state.dart';
|
||||
export 'loggy.dart';
|
||||
export 'phono_byte.dart';
|
||||
export 'radix_generator.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue