Link class

A tappable widget that triggers Unrouter navigation.

Link is a lightweight Flutter widget alternative to imperative navigation calls from button handlers. It resolves to with the same rules as router navigation: route name first, then absolute path.

If replace is true, the tap uses replace; otherwise it uses push.

Example:

Link(
  to: 'user',
  params: {'id': '42'},
  query: URLSearchParams('tab=profile'),
  state: const {'source': 'home'},
  child: const Text('Open profile'),
)

See also:

  • Unrouter.push, which performs imperative push navigation.
  • Unrouter.replace, which replaces the current history entry.
Inheritance

Constructors

Link({required String to, required Widget child, Map<String, String>? params, URLSearchParams? query, Object? state, bool replace = false, bool enabled = true, VoidCallback? onTap, HitTestBehavior behavior = HitTestBehavior.deferToChild, Key? key})
Creates a navigation link.
const

Properties

behavior → HitTestBehavior
Hit test behavior used by the internal GestureDetector.
final
child → Widget
Child widget used as the tap target.
final
enabled → bool
Whether tap interaction is enabled.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onTap → VoidCallback?
Callback invoked before navigation is triggered.
final
params → Map<String, String>?
Params used when to resolves as a route name.
final
query → URLSearchParams?
Query params merged into the destination URI.
final
replace → bool
Whether to use replace navigation instead of push navigation.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
state → Object?
Navigation state forwarded to the destination history entry.
final
to → String
Route name or absolute path to navigate to.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
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