flutter_ulink_sdk 0.0.2 copy "flutter_ulink_sdk: ^0.0.2" to clipboard
flutter_ulink_sdk: ^0.0.2 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
  • Support for custom API configuration
  • Test utilities for easier development and testing

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',
      baseUrl: 'https://api.ulink.ly', // Use 'http://localhost:3000' for local testing
      debug: true, // Enable debug logging
    ),
  );
  
  runApp(MyApp());
}

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
}

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;
    });
  });
}

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}');
}

Testing #

For testing with localhost:

// Initialize with localhost URL
final ulink = await ULink.initialize(
  config: ULinkConfig(
    apiKey: 'your_api_key',
    baseUrl: 'http://localhost:3000',
    debug: true,
  ),
);

// Test the link listener
await ulink.testListener('http://localhost:3000/d/test-slug');

API Endpoints #

The SDK uses the following API endpoints:

  • Create link: POST /sdk/links
  • Resolve link: GET /sdk/resolve?url=...

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.

3
likes
0
points
419
downloads

Publisher

verified publisherbeingthere.dev

Weekly Downloads

Flutter SDK for creating and handling dynamic links, similar to Branch.io

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

app_links, flutter, http, shared_preferences, uuid

More

Packages that depend on flutter_ulink_sdk