urlynk_flutter 1.3.3 copy "urlynk_flutter: ^1.3.3" to clipboard
urlynk_flutter: ^1.3.3 copied to clipboard

A Flutter plugin for deferred deep links and URL shortening, with the option to use your own branded domains.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:urlynk_flutter/urlynk_flutter.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 _urlynk = UrlynkFlutter();

  @override
  void initState() {
    super.initState();
    _init();
  }

  @override
  void dispose() {
    _urlynk.dispose();
    super.dispose();
  }

  Future<void> _init() async {
    // Configure URLynk service. Must be called before using any other methods.
    await _urlynk.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
    log('URLynk configured successfully');

    // Listen for deep link data
    _urlynk.onLinkData.listen(
      (res) => log('Received Data: [${res.link}] ${res.data}'),
      onError: (e) => log('Received Data Error: ${e.message}'),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('URLynk Example')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: _createDeepLink,
                child: const Text('Create Deep Link'),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: _createShortLink,
                child: const Text('Create Short Link'),
              ),
              const SizedBox(height: 20),
              StreamBuilder<ReceivedData>(
                stream: _urlynk.onLinkData,
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.active) {
                    final res = snapshot.data;
                    final error = snapshot.error as PlatformException?;
                    return Text(
                      error == null
                          ? 'Received Data: [${res?.link}] ${res?.data}'
                          : 'Received Data Error: ${error.message}',
                    );
                  }
                  return const Text('Waiting for link data...');
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> _createDeepLink() async {
    try {
      final deepLink = await _urlynk.createDeepLink(
        jsonEncode({'referredBy': '12345', 'referralCode': 'WELCOME50'}),
      );
      if (deepLink != null) log('Deep link created: $deepLink');
    } on PlatformException catch (e) {
      log(e.message ?? '');
    }
  }

  Future<void> _createShortLink() async {
    try {
      // final now = DateTime.now().toUtc().millisecondsSinceEpoch;
      final shortLink = await _urlynk.createShortLink(
        LinkModel(
          url: 'https://www.google.com/search?q=urlynk',
          // id: 'sX85',
          // password: 'Test@123',
          // domain: 'urlynk.in',
          // webhookURL: "https://your.domain.com/webhook",
          // startTime: now + 60 * 60 * 1000, // activates after 1 hour from now
          // expiry: [
          //   ExpiryModel(type: ExpiryType.clickBased, value: 100),
          //   ExpiryModel(
          //     type: ExpiryType.timeBased,
          //     value: now + 25 * 60 * 60 * 1000,
          //   ),
          // ],
          // restrictions: RestrictionModel(
          //   clicksPerDevice: 1,
          //   os: [OSType.android, OSType.ios, OSType.macos],
          //   devices: [DeviceType.mobile, DeviceType.desktop],
          //   workingHrs: [WorkingHrModel(startHr: 10, endHr: 20)],
          //   inclLoc: [
          //     LocModel(
          //       address: 'India',
          //       boundingBox: [6.5531169, 35.6745457, 67.9544415, 97.395561],
          //     ),
          //   ],
          //   exclLoc: [],
          // ),
          // smartRouting: SmartRoutingModel(
          //   osBased: [
          //     RoutingModel(
          //       url: 'https://www.microsoft.com',
          //       targets: [OSType.android],
          //     ),
          //   ],
          //   deviceBased: [
          //     RoutingModel(
          //       url: 'https://www.amazon.com/s?k=smartphones',
          //       targets: [DeviceType.desktop],
          //     ),
          //   ],
          //   timeBased: [
          //     RoutingModel(
          //       url: 'https://www.epochconverter.com',
          //       targets: [WorkingHrModel(startHr: 12, endHr: 15)],
          //     ),
          //   ],
          //   locBased: [
          //     RoutingModel(
          //       url: 'https://www.google.com/maps',
          //       targets: [
          //         LocModel(
          //           address: 'India',
          //           boundingBox: [6.5531169, 35.6745457, 67.9544415, 97.395561],
          //         ),
          //       ],
          //     ),
          //   ],
          // ),
        ),
      );
      if (shortLink != null) log('Short link created: $shortLink');
    } on PlatformException catch (e) {
      log(e.message ?? '');
    }
  }
}
6
likes
160
points
563
downloads

Publisher

verified publishervalueoutput.com

Weekly Downloads

A Flutter plugin for deferred deep links and URL shortening, with the option to use your own branded domains.

Homepage
Repository (GitHub)
View/report issues

Topics

#deeplink #deep-link #dynamic-links #app-links #universal-links

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, flutter_web_plugins, http, plugin_platform_interface

More

Packages that depend on urlynk_flutter

Packages that implement urlynk_flutter