Flutter integration

Create sharing links in your Flutter application

Allowing your users to share content directly from your application is an excellent way to

  • Acquire new users.
  • Increase engagement and retention.

Thanks to the Weespin package, you can generate personalized and tracked sharing links, integrating deep links to redirect your users to a specific page or feature in your app.

Prerequisites: Get your API keys

  1. Log into your Weespin dashboard.
  2. Go to your application.
  3. Go to the Configuration section.
  4. In Integration:
    • Generate the API key that will be used to identify your application.

Integrate the Weespin plugin

  1. Add the dependency in pubspec.yaml:
    dependencies:
      weespin: ^1.0.0
    
  2. Import the package in your Dart code:
    import 'package:weespin/weespin.dart';
    

Here is a concrete example for creating a link with custom parameters:

Future<void> createLink() async {
  try {
    final response = await Weespin(
      apiKey: 'YOUR_API_KEY',
    ).createLink(
      title: "My link",
      description: "Test description",
      segments: ["news", "bananas"],
      customParams: ["utm", "productId"],
    );

    print("βœ… Response: $response");

    final shareLink = response.shareLink({
      "utm": '1221',
      "productId": '434',
    });

    print("βœ… shareLink: $shareLink");
  } catch (e) {
    print("❌ Error while creating link: $e");
  }
}

You can then trigger this from a share button:

ElevatedButton(
  onPressed: createLink,
  child: const Text('Share this content'),
)

To handle deep links (open a specific screen when the user clicks a generated link), use the app_links package.

  1. Add the dependency in pubspec.yaml:
dependencies:
  app_links: ^0.5.1 # or newer

Android configuration

In android/app/src/main/AndroidManifest.xml:

<activity
  android:name=".MainActivity"
  android:launchMode="singleTop"
  android:exported="true">

  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
      android:scheme="https"
      android:host="yourdomain.com" />
  </intent-filter>
</activity>

iOS configuration

In ios/Runner/Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>yourapp</string>
    </array>
  </dict>
</array>
<key>FlutterDeepLinkingEnabled</key>
<false/>

Then in Xcode:

  • Select your project > Target > "Signing & Capabilities"
  • Add the Associated Domains capability
  • Add to the list:
    • applinks:yourdomain.com

Example usage in Flutter

random/file/name.dart
import 'dart:async';
import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final GlobalKey<NavigatorState> _navKey = GlobalKey<NavigatorState>();
  StreamSubscription<Uri>? _sub;

  @override
  void initState() {
    super.initState();
    _sub = AppLinks().uriLinkStream.listen((Uri uri) {
      final String path = uri.fragment; // e.g. /promo/123
      if (path.startsWith('/promo/')) {
        _navKey.currentState?.pushNamed(path);
      }
    });
  }

  @override
  void dispose() {
    _sub?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: _navKey,
      initialRoute: '/',
      onGenerateRoute: (RouteSettings settings) {
        final String route = settings.name ?? '/';
        if (route.startsWith('/promo/')) {
          final String id = route.replaceFirst('/promo/', '');
          return MaterialPageRoute(builder: (_) => PromoScreen(id: id));
        }
        return MaterialPageRoute(builder: (_) => const HomeScreen());
      },
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('🏠 Home')),
      body: const Center(
        child: Text('Use a link like /promo/123 to test.'),
      ),
    );
  }
}

class PromoScreen extends StatelessWidget {
  final String id;
  const PromoScreen({super.key, required this.id});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('🎯 Promo')),
      body: Center(child: Text('Promo product ID: $id')),
    );
  }
}

Test on Android and iOS

  1. Android: test sharing via SMS, WhatsApp, or Gmail.
  2. iOS: test via iMessage, Mail, or social apps.
  3. Verify that:
    • The link correctly redirects to the app or the website.
    • Deep links work and open the exact content.
    • The UX is smooth without excessive loading time.

Conclusion / Tips

By integrating sharing links with Weespin:

  • You increase the viral reach of your application.
  • You create a smooth user journey to your content.
  • You collect conversion and engagement data via tracked deep links.

Start building now

Create seamless sharing experiences in your Flutter app with Weespin integration

::