updateMeta method
void
updateMeta({
- String? title,
- String? description,
- String? keywords,
- String? canonicalUrl,
- String? author,
- String? ogTitle,
- String? ogDescription,
- String? ogImage,
- String? ogImageWidth,
- String? ogImageHeight,
- String? ogType,
- String? ogUrl,
- String? ogSiteName,
- String? twitterCard,
- String? twitterTitle,
- String? twitterDescription,
- String? twitterImage,
- String? twitterSite,
- String? twitterCreator,
- String? robots,
- Map<
String, String> ? customMeta, - Map<
String, String> ? customPropertyMeta,
Update page meta tags.
Call this when navigating to a new page, or use the SeoHead widget for declarative management.
Webify.instance.updateMeta(
title: 'Product Name',
description: 'Amazing product description',
ogImage: 'https://example.com/product.png',
);
Implementation
void updateMeta({
String? title,
String? description,
String? keywords,
String? canonicalUrl,
String? author,
// Open Graph
String? ogTitle,
String? ogDescription,
String? ogImage,
String? ogImageWidth,
String? ogImageHeight,
String? ogType,
String? ogUrl,
String? ogSiteName,
// Twitter / X
String? twitterCard,
String? twitterTitle,
String? twitterDescription,
String? twitterImage,
String? twitterSite,
String? twitterCreator,
// Robots
String? robots,
// Custom
Map<String, String>? customMeta,
Map<String, String>? customPropertyMeta,
}) {
// Title
if (title != null) {
final fullTitle = _config.titleTemplate != null
? _config.titleTemplate!.replaceAll('%s', title)
: title;
_platform.setTitle(fullTitle);
_currentTitle = fullTitle;
}
// Standard meta tags
_setIfNotNull('description', description);
_setIfNotNull('keywords', keywords);
_setIfNotNull('author', author);
_setIfNotNull('robots', robots);
// Canonical
if (canonicalUrl != null) {
_platform.setCanonicalUrl(canonicalUrl);
}
// Open Graph
_setPropertyIfNotNull('og:title', ogTitle ?? title);
_setPropertyIfNotNull('og:description', ogDescription ?? description);
_setPropertyIfNotNull('og:image', ogImage);
_setPropertyIfNotNull('og:image:width', ogImageWidth);
_setPropertyIfNotNull('og:image:height', ogImageHeight);
_setPropertyIfNotNull('og:type', ogType);
_setPropertyIfNotNull('og:url', ogUrl ?? canonicalUrl);
_setPropertyIfNotNull('og:site_name', ogSiteName);
// Twitter
_setIfNotNull('twitter:card', twitterCard);
_setIfNotNull('twitter:title', twitterTitle ?? ogTitle ?? title);
_setIfNotNull(
'twitter:description',
twitterDescription ?? ogDescription ?? description,
);
_setIfNotNull('twitter:image', twitterImage ?? ogImage);
_setIfNotNull('twitter:site', twitterSite ?? _config.twitterSite);
_setIfNotNull('twitter:creator', twitterCreator);
// Custom name-based meta tags
customMeta?.forEach((name, content) {
_platform.setMetaTag(name, content);
_currentMeta[name] = content;
});
// Custom property-based meta tags
customPropertyMeta?.forEach((property, content) {
_platform.setPropertyMetaTag(property, content);
_currentMeta[property] = content;
});
// Debug logging
if (_config.debugMode) {
debugPrint(
'[webify] Meta updated: title="$title", '
'description="${description?.substring(0, (description.length > 50 ? 50 : description.length))}..."',
);
}
}