SignalContainer<T, Arg, S extends ReadonlySignalMixin<T> > class
Signal container used to create signals based on args
final container = readonlySignalContainer<Cache, String>((e) {
return signal(Cache(e));
});
final cacheA = container('cache-a');
final cacheB = container('cache-b');
final cacheC = container('cache-c');
Example of settings and SharedPreferences:
class Settings {
final SharedPreferences prefs;
EffectCleanup? _cleanup;
Settings(this.prefs) {
_cleanup = effect(() {
for (final entry in setting.store.entries) {
final value = entry.value.peek();
if (prefs.getString(entry.key.$1) != value) {
prefs.setString(entry.key.$1, value).ignore();
}
}
});
}
late final setting = signalContainer<String, (String, String)>(
(val) => signal(prefs.getString(val.$1) ?? val.$2),
cache: true,
);
Signal<String> get darkMode => setting(('dark-mode', 'false'));
void dispose() {
_cleanup?.call();
setting.dispose();
}
}
void main() {
// Load or find instance
late final SharedPreferences prefs = ...;
// Create settings
final settings = Settings(prefs);
// Get value
print('dark mode: ${settings.darkMode}');
// Update value
settings.darkMode.value = 'true';
}
Constructors
- SignalContainer(S _create(Arg), {bool cache = false})
- Signal container used to create multiple signals via args
Properties
Methods
-
call(
Arg arg) → S - Create the signal with the given args
-
clear(
) → void - Clear the cache
-
containsKey(
Arg arg) → bool - Check if signal is currently stored in the cache
-
dispose(
) → void - Dispose of all created signals
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
Arg arg) → S? - Remove a signal from the cache
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited