Link Creation
Generate smart links programmatically in your Flutter app
Generating a link
Use generateLink to create a smart link with optional metadata, tracking, and redirects. It returns the link URL as a String:
import 'package:flutter/foundation.dart';
import 'package:grovs_flutter_plugin/grovs.dart';
import 'package:grovs_flutter_plugin/models/grovs_link.dart';
final grovs = Grovs();
Future<String> createShareLink() async {
try {
final link = await grovs.generateLink(
GenerateLinkParams(
title: 'Check out this product',
subtitle: 'Limited time offer',
imageURL: 'https://example.com/image.jpg',
data: {
'screen': 'product',
'productId': '12345',
},
tags: ['promotion', 'share'],
tracking: TrackingParams(
utmCampaign: 'spring_sale',
utmSource: 'in_app',
utmMedium: 'share_button',
),
),
);
debugPrint('Generated: $link');
return link;
} on GrovsException catch (e) {
debugPrint('Error: ${e.message} (${e.code})');
rethrow;
}
}Link generation needs the SDK to be configured, enabled, and authenticated. A failure surfaces as a GrovsException whose code is GENERATION_ERROR; the message carries the native error text on Android and a generic message on iOS.
Parameters
| Parameter | Type | Description |
|---|---|---|
title | String | Link preview title (required) |
subtitle | String? | Link preview subtitle |
imageURL | String? | Link preview image URL |
data | Map<String, dynamic>? | Custom payload delivered on deep link open |
tags | List<String>? | Tags for filtering and analytics |
customRedirects | CustomRedirects? | Override the default redirect per platform. See Custom redirects |
showPreviewIos | bool? | Show the link preview page on iOS. null uses the project default |
showPreviewAndroid | bool? | Show the link preview page on Android. null uses the project default |
copyToClipboardIos | bool? | Copy the link to the clipboard from the preview page on iOS, for clipboard-assisted deferred deep linking. null inherits the project setting |
copyToClipboardAndroid | bool? | Same, for Android. null inherits the project setting |
tracking | TrackingParams? | UTM campaign, source, and medium |
copyToClipboardIos and copyToClipboardAndroid only take effect when the preview page is shown for that platform. Passing false is an explicit override, not the same as omitting the parameter. The project-level setting and what the visitor sees are described in Copy to Clipboard.
On Android, payload values in data that are strings, numbers, booleans, or otherwise serializable are passed through as they are; anything else is converted with toString(). On iOS the map is passed through unchanged.
Custom redirects
Override where a link sends users on each platform:
final link = await grovs.generateLink(
GenerateLinkParams(
title: 'Special offer',
data: {'promoId': 'summer25'},
customRedirects: CustomRedirects(
ios: CustomLinkRedirect(url: 'https://example.com/ios-promo'),
android: CustomLinkRedirect(url: 'https://example.com/android-promo'),
desktop: CustomLinkRedirect(
url: 'https://example.com/desktop-promo',
openAppIfInstalled: false,
),
),
),
);When openAppIfInstalled is true (the default), the app opens if it is installed and the redirect URL is used otherwise. When false, the redirect URL is always used.
Sharing the link
Launch the platform share sheet once the link is generated, for example with the share_plus package:
import 'package:share_plus/share_plus.dart';
final link = await grovs.generateLink(
GenerateLinkParams(title: 'Share this', data: {'itemId': 'abc'}),
);
await Share.share(link);