Classes
The following classes are available globally.
-
A key is an object that is used to compare widgets for equality. Differences will cause the widget to be rebuilt.
You can create your own keys by subclassing it and implementing
Key.equals
andKey.hashValue
. This default implementation compares keys via object identity.Note that, in 99% of cases, you’ll want to use
See moreAutoKey
instead. -
A
Key
that takes a hashable object and wraps it, forwarding equality and hashValue tests to the underlying object. A common pattern you’ll see in Amai code is:struct MyWidget: StatelessWidget, HashableWidget { var key: Key = NullKey() init() { self.key = AutoKey(self) } }
Here, the widget’s
See moreAutoKey
wraps itself. -
The core build context, passed around between widgets for building.
See more -
A signal handler that can be attached to widget signals. These should be created once per widget in order to avoid needless widget rebuilds.
See more -
Like a
Handler
, except it calls an unbound method that must be later bound. Example:
See moreclass MyWidget: StatelessWidget, HashableWidget { func onClick() {} static let onClickHandler = MethodHandler(onClick) ... func build(ctx: BuildContext) -> Widget { return Button( Button.onClick => MyWidget.onClickHandler.bind(to: self) ) } }