Classes

The following classes are available globally.

  • Key

    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 and Key.hashValue. This default implementation compares keys via object identity.

    Note that, in 99% of cases, you’ll want to use AutoKey instead.

    See more
  • A Key that’s always equal to any other NullKey. This is primarily a stub used for default initialization so that you can later use an AutoKey instead.

    See more
  • 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 AutoKey wraps itself.

    See more
  • 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:

    class MyWidget: StatelessWidget, HashableWidget {
        func onClick() {}
        static let onClickHandler = MethodHandler(onClick)
        ...
        func build(ctx: BuildContext) -> Widget {
            return Button(
                Button.onClick => MyWidget.onClickHandler.bind(to: self)
            )
    }
    }
    
    See more
  • A wrapper over a Widget that allows you to store them in a Hashable type.

    See more