SwiftController class abstract
Base class for controllers that manage state.
Controllers are the only place where state can be modified. Views can only read state - values are automatically read-only from views.
Example:
class CounterController extends SwiftController {
// Just use swift() - automatically read-only from views!
final counter = swift(0);
final name = swift('Hello');
// Only controllers can modify state
void increment() => counter.value++;
void updateName(String n) => name.value = n;
}
// In view:
class MyView extends StatefulWidget {
@override
Widget build(BuildContext context) {
final controller = CounterController();
return Swift(
builder: (context) => Text('${controller.counter.value}'),
);
// ✅ Can read: controller.counter.value
// ✅ Can call: controller.increment()
// ❌ Cannot modify: controller.counter.value = 10 (runtime error)
}
}
- Inheritance
-
- Object
- ChangeNotifier
- SwiftController
- Available extensions
Constructors
- SwiftController()
- Constructor
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isDisposed → bool
-
Check if controller is disposed
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
notifyListenersTransaction(
) → void -
Available on ChangeNotifier, provided by the TransactionNotifier extension
Notifies listeners, respecting transaction context. -
readOnly<
T> (SwiftValue< T> swift) → ReadOnlyRx<T> - Create a read-only wrapper for a SwiftValue This is a convenience method that also registers it for disposal
-
registerReadOnlyRx<
T> (ReadOnlyRx< T> readOnlyRx) → void - Register a ReadOnlyRx to be automatically disposed
-
registerRx<
T> (SwiftValue< T> swift) → void - Register a SwiftValue to be automatically disposed This is optional - you can manage disposal manually if preferred
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
swift<
T> (T value, {String? name}) → ControllerRx< T> - Create a swift value that's automatically read-only from views Use this instead of the global swift() function in controllers
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited