updateMeta method

void updateMeta({
  1. String? title,
  2. String? description,
  3. String? keywords,
  4. String? canonicalUrl,
  5. String? author,
  6. String? ogTitle,
  7. String? ogDescription,
  8. String? ogImage,
  9. String? ogImageWidth,
  10. String? ogImageHeight,
  11. String? ogType,
  12. String? ogUrl,
  13. String? ogSiteName,
  14. String? twitterCard,
  15. String? twitterTitle,
  16. String? twitterDescription,
  17. String? twitterImage,
  18. String? twitterSite,
  19. String? twitterCreator,
  20. String? robots,
  21. Map<String, String>? customMeta,
  22. 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))}..."',
    );
  }
}