KaiselConfigCodec<R extends KaiselRoute> class abstract

Maps URLs to and from a full KaiselConfig.

Supersedes KaiselStackCodec when you want URLs to address state inside a nested router (shell or module). A KaiselConfigCodec returns / accepts the outer configuration; the codec decides how to flatten the nested state into the URL path (and back).

If you don't need nested URLs, keep your existing KaiselStackCodec and pass it via KaiselRouteInformationParser.fromStackCodec.

class AppCodec implements KaiselConfigCodec<AppRoute> {
  const AppCodec();

  @override
  Uri encode(KaiselConfig<AppRoute> config) {
    return switch ((config.mainStack.last, config.nestedState)) {
      (Splash(), _)   => Uri(path: '/'),
      (Login(), _)    => Uri(path: '/login'),
      (Settings(), _) => Uri(path: '/settings'),
      (MainShell(), final KaiselShellConfig shell) => _encodeShell(shell),
      (CheckoutMount(), final KaiselModuleConfig m) => _encodeCheckout(m),
      _ => Uri(path: '/'),
    };
  }
  // ... decode
}
Implementers

Constructors

KaiselConfigCodec()
Const constructor so subclasses can be const.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decode(Uri uri) KaiselConfig<R>?
Decode a URL into a configuration, or return null if unrecognised (the parser will then use the fallback stack).
encode(KaiselConfig<R> config) Uri
Encode a configuration into a URL.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited