Hello All
I am trying to update the meta property of the web deploiement of my flutterflow app. The goal is to have the title of my page, the description, the image of my page and the url to be visible when I share on whatsapp or another plattform. The problem is that even I succeeded to update the meta with this code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:html'; // For DOM manipulation
Future<void> shareAction(
BuildContext context,
String? title,
String? description,
String? imageUrl,
String? url,
) async {
// Ensure all required parameters are provided
if (title == null || description == null || imageUrl == null || url == null) {
print("Error: One or more meta tag parameters are missing.");
return;
}
// Set meta tags directly with the provided parameters
setMetaTags(
title: title,
description: description,
imageUrl: imageUrl,
url: url,
appTitle: "CMFI Replay", // App title for Apple meta tags
statusBarStyle: "black", // Status bar style for Apple devices
isAppCapable: "yes", // Enable web app mode on Apple devices
);
// Dispatch a custom event to notify that metadata has been updated
document.dispatchEvent(Event('custom-metadata-loaded'));
}
void setMetaTags({
required String title,
required String description,
required String imageUrl,
required String url,
required String appTitle,
required String statusBarStyle,
required String isAppCapable,
}) {
// Define a helper function to update or create meta tags
void updateMetaTag(
String attributeType, String attributeValue, String content) {
final tag = document
.querySelector('meta[$attributeType="$attributeValue"]') ??
MetaElement()
..setAttribute(attributeType, attributeValue);
tag.setAttribute('content', content);
if (tag.parent == null) {
document.head?.append(tag);
}
}
// Update Open Graph (OG) meta tags
updateMetaTag('property', 'og:title', title);
updateMetaTag('property', 'og:description', description);
updateMetaTag('property', 'og:image', imageUrl);
updateMetaTag('property', 'og:url', url);
// Update Twitter meta tags
updateMetaTag('name', 'twitter:title', title);
updateMetaTag('name', 'twitter:description', description);
updateMetaTag('name', 'twitter:image', imageUrl);
updateMetaTag('name', 'twitter:card', 'summary_large_image xxx');
// Update Apple meta tags
updateMetaTag('name', 'apple-mobile-web-app-capable', isAppCapable);
updateMetaTag(
'name', 'apple-mobile-web-app-status-bar-style', statusBarStyle);
updateMetaTag('name', 'apple-mobile-web-app-title', title);
// Update general description meta tag
updateMetaTag('name', 'description', description);
}
The problem is still existing as the default html code doesn't have the meta updated. So how can I set the meta in the default html generated from flutterflow to the web ?