SeoImage class
A widget that displays an image and injects a corresponding HTML <img>
element into the DOM for SEO purposes when running on the web.
This is useful because Flutter's default rendering on web uses a canvas, which is not SEO-friendly for search engines. By implementing SeoInjectable, this widget ensures that search engine crawlers can read and index the image's HTML representation.
Example usage:
SeoImage(
src: 'https://example.com/image.jpg',
alt: 'Example image',
width: 200,
height: 150,
)
When running on the web, this will also create an HTML <img> element
with the specified attributes and inject it into the DOM.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- SeoImage
- Implemented types
Constructors
- SeoImage({required String src, String? alt, double? width, double? height, BoxFit? fit, AlignmentGeometry alignment = Alignment.center, ImageRepeat repeat = ImageRepeat.noRepeat, String? semanticLabel, bool excludeFromSemantics = false, String? id, void onTap()?, Key? key})
-
Creates a SeoImage widget.
const
Properties
- alignment → AlignmentGeometry
-
How to align the image within its bounds.
final
- alt → String?
-
The alternative text for the image, used by screen readers and SEO.
If not provided, semanticLabel is used instead.
final
- excludeFromSemantics → bool
-
Whether to exclude the image from semantics.
final
- fit → BoxFit?
-
How to inscribe the image into the space allocated during layout.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
The height of the image (both in Flutter and in the HTML element).
final
- id → String?
-
The
idattribute of the HTML<img>element. If not provided, a random ID will be generated.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onTap → void Function()?
-
Optional callback triggered when the link is tapped in Flutter.
final
- repeat → ImageRepeat
-
How to paint any portions of the image that do not fit inside the box.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticLabel → String?
-
A label for the image used by screen readers.
final
- src → String
-
The URL of the image to display.
final
- width → double?
-
The width of the image (both in Flutter and in the HTML element).
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
-
createHtmlElement(
) → WebHTMLElement? -
Creates and returns a WebHTMLElement to represent this object in the DOM.
override
-
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