Link class

A widget that navigates to a specified route when tapped.

Link provides a declarative way to create navigation links in your app. It handles tap gestures, accessibility semantics, and mouse cursor behavior automatically.

Basic usage with a child widget:

Link(
  path: '/about',
  child: const Text('About Us'),
)

For more control, use builder:

Link(
  path: '/products/1',
  state: {'source': 'homepage'},
  builder: (context, location, navigate) {
    return GestureDetector(
      onTap: () => navigate(),
      onLongPress: () => navigate(replace: true),
      child: Text('Product 1'),
    );
  },
)
Inheritance

Constructors

Link({Key? key, String? name, String? path, Map<String, String> params = const {}, Map<String, String>? query, String? fragment, Widget? child, LinkBuilder? builder, bool replace = false, Object? state})
Creates a link that navigates to name or path when tapped.
const

Properties

builder LinkBuilder?
The builder function for custom link rendering.
final
child Widget?
The widget to display for the link.
final
fragment String?
Fragment to append to the URI.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
name String?
The named route to navigate to.
final
params Map<String, String>
Params for named routes or path patterns.
final
path String?
The path to navigate to.
final
query Map<String, String>?
Query parameters to append to the URI.
final
replace bool
Whether to replace the current history entry instead of pushing a new one.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state Object?
Optional state to associate with the navigation.
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