Pylon<T> class
A widget that provides a value of type T to its descendants in the widget tree.
Pylon is a state management solution that allows values to be passed down the widget tree and accessed by descendant widgets without the need for explicit passing through constructor parameters. It is designed to be simple, reliable, and intuitive, working similarly to but more reliably than the Provider package.
Key features:
- Provides values to descendant widgets
- Can be accessed across navigation routes
- Supports builders for immediate access to values
- Can be combined with other pylons using PylonCluster
Descendant widgets can access the value using BuildContext extensions like:
context.pylon<T>()- Get the value (throws if not found)context.pylonOr<T>()- Get the value or null if not foundcontext.hasPylon<T>()- Check if a pylon of type T is available
- Inheritance
Constructors
- Pylon({Key? key, required T value, required PylonBuilder? builder, bool local = false})
-
Creates a Pylon widget with a builder function.
const
- Pylon.data({Key? key, required T value, bool local = false})
-
Creates a Pylon widget with only data, no child or builder.
const
- Pylon.withChild({Key? key, required T value, required Widget? child, bool local = false})
-
Creates a Pylon widget with a child widget.
const
Properties
- builder → PylonBuilder?
-
Optional builder function to create a child widget with access to the pylon value.
If provided, child must be null.
final
- child → Widget?
-
Optional child widget. If provided, builder must be null.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- local → bool
-
If true, this pylon won't be transferred across navigation routes.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
The value of type
Tthat will be provided to descendant widgets.final - valueType → Type
-
Returns the type of value stored in this pylon.
no setter
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
copyWithBuilder(
PylonBuilder builder) → Pylon< T> -
Returns a copy of this widget with the builder function set to
builder. -
copyWithChild(
Widget child) → Pylon< T> -
Returns a copy of this widget with the child widget set to
child. -
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
cupertinoPageRoute<
T extends Object?> (BuildContext context, Widget builder(BuildContext), {RouteSettings? settings}) → CupertinoPageRoute< T> - Creates a CupertinoPageRoute with all pylon values from the current context transferred to the new route.
-
materialPageRoute<
T extends Object?> (BuildContext context, Widget builder(BuildContext), {RouteSettings? settings}) → MaterialPageRoute< T> - Creates a MaterialPageRoute with all pylon values from the current context transferred to the new route.
-
mirror(
BuildContext context, Widget builder(BuildContext)) → Widget Function(BuildContext) - Creates a builder function that incorporates all visible pylon values from the current context.
-
push<
T extends Object?> (BuildContext context, Widget child, {RouteSettings? settings, PylonRouteType type = PylonRouteType.material, Route< T> ? route}) → Future<T?> - Pushes a new route to the navigator with all visible Pylon widgets from the current context.
-
pushAndRemoveUntil<
T extends Object?> (BuildContext context, Widget child, {RouteSettings? settings, PylonRouteType type = PylonRouteType.material, Route< T> ? route, required RoutePredicate predicate}) → Future<T?> -
Pushes a new route and removes routes until
predicatereturns true, transferring pylon values. -
pushReplacement<
T extends Object?, TO extends Object?> (BuildContext context, Widget child, {RouteSettings? settings, PylonRouteType type = PylonRouteType.material, Route< T> ? route}) → Future<T?> - Replaces the current route with a new one, transferring pylon values.
-
visiblePylons(
BuildContext context, {bool ignoreLocals = false}) → List< Pylon> -
Returns a list of all visible Pylon widgets in the widget tree, starting from
context. -
widgetOf<
T> (BuildContext context) → Pylon< T> -
Returns the value of the nearest ancestor Pylon widget of type
Tor throws an error if not found. -
widgetOfOr<
T> (BuildContext context) → Pylon< T> ? -
Returns the value of the nearest ancestor Pylon widget of type
Tor null if not found.