FloatyStateChannel<S> class
final
A typed, auto-syncing state channel between the main app and overlay.
Define a state class with toJson/fromJson and let the channel keep
both sides in sync:
final channel = FloatyStateChannel<MyState>(
toJson: (s) => s.toJson(),
fromJson: MyState.fromJson,
initialState: MyState(),
);
await channel.setState(MyState(count: 1));
await channel.updateState({'count': 2});
channel.onStateChanged.listen(print);
Use FloatyStateChannel.overlay on the overlay side. Both sides must use the same state type and serialization. updateState performs a shallow merge of top-level keys; nested objects are replaced.
Constructors
-
FloatyStateChannel({required Map<
String, dynamic> toJson(S state), required S fromJson(Map<String, dynamic> json), required S initialState}) -
Creates a state channel for the main app side.
factory
-
FloatyStateChannel.overlay({required Map<
String, dynamic> toJson(S state), required S fromJson(Map<String, dynamic> json), required S initialState}) -
Creates a state channel for the overlay side.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
onStateChanged
→ Stream<
S> -
Stream of state changes from the other side.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → S
-
The current state (synchronous read).
no setter
Methods
-
dispose(
) → Future< void> - Releases resources.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setState(
S newState) → Future< void> - Replaces the entire state and syncs to the other side.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateState(
Map< String, dynamic> partial) → Future<void> -
Shallow-merges
partialinto the current state's JSON, rebuilds the state, and syncs to the other side.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited