flutter_ulink_sdk 0.0.3
flutter_ulink_sdk: ^0.0.3 copied to clipboard
Flutter SDK for creating and handling dynamic links, similar to Branch.io
ULink SDK for Flutter #
A Flutter SDK for creating and handling dynamic links with ULink, similar to Branch.io.
Features #
- Create dynamic links with custom slugs and parameters
- Social media tag support for better link sharing
- Automatic handling of dynamic links in your app
- Resolve links to retrieve their data
Installation #
Add this to your pubspec.yaml dependencies:
dependencies:
flutter_ulink_sdk: ^1.0.0
Setup #
Initialize the SDK #
Initialize the SDK in your app:
import 'package:flutter_ulink_sdk/flutter_ulink_sdk.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize with production defaults
final ulink = await ULink.initialize();
// Or with custom config
final ulink = await ULink.initialize(
config: ULinkConfig(
apiKey: 'your_api_key',
debug: true, // Enable debug logging
),
);
runApp(MyApp());
}
Creating Dynamic Links #
Create dynamic links with custom parameters:
final response = await ULink.instance.createLink(
ULinkParameters(
slug: 'product-123',
iosFallbackUrl: 'myapp://product/123',
androidFallbackUrl: 'myapp://product/123',
fallbackUrl: 'https://myapp.com/product/123',
socialMediaTags: SocialMediaTags(
ogTitle: 'Check out this awesome product!',
ogDescription: 'This is a detailed description of the product.',
ogImage: 'https://example.com/product-image.jpg',
),
parameters: {
'utm_source': 'share_button',
'campaign': 'summer_sale',
},
),
);
if (response.success) {
final dynamicLinkUrl = response.url;
// Use the dynamic link URL
} else {
final error = response.error;
// Handle error
}
Handling Dynamic Links #
Listen for dynamic links in your app:
@override
void initState() {
super.initState();
// Listen for incoming links
ULink.instance.onLink.listen((ULinkResolvedData data) {
setState(() {
// Access link data
final slug = data.slug;
final fallbackUrl = data.fallbackUrl;
final parameters = data.parameters;
final socialMediaTags = data.socialMediaTags;
final rawData = data.rawData;
});
});
}
Resolving Links Manually #
Resolve a dynamic link to get its data:
// Resolve a ULink format URL (d/slug)
final resolveResponse = await ULink.instance.resolveLink('https://ulink.ly/d/your-slug');
if (resolveResponse.success) {
final resolvedData = ULinkResolvedData.fromJson(resolveResponse.data!);
// Use the resolved data
print('Slug: ${resolvedData.slug}');
print('Fallback URL: ${resolvedData.fallbackUrl}');
print('Parameters: ${resolvedData.parameters}');
} else {
// Handle error
print('Error: ${resolveResponse.error}');
}
Example Project #
Check out the example project in the example directory for a complete implementation.
License #
This project is licensed under the MIT License - see the LICENSE file for details.