appsonair_flutter_applink 1.2.4 copy "appsonair_flutter_applink: ^1.2.4" to clipboard
appsonair_flutter_applink: ^1.2.4 copied to clipboard

The AppsOnAir AppLink Flutter SDK enables deep link tracking and engagement analytics for both iOS and Android. It serves as a powerful alternative to Firebase Dynamic Links.

example/lib/main.dart

import 'dart:developer';
import 'package:appsonair_flutter_applink/models/app_link_params.dart';
import 'package:flutter/material.dart';

import 'package:appsonair_flutter_applink/appsonair_flutter_applink.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _linkDetails = '';
  final _appsonairFlutterApplinkPlugin = AppsonairFlutterApplink();
  TextEditingController txtController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _appsonairFlutterApplinkPlugin.initializeAppLink().listen((event) {
      setState(() {
        _linkDetails = event.toString(); // Update UI with deep link
      });
    });
    _appsonairFlutterApplinkPlugin.onReferralLinkDetected().listen((event) {
      setState(() {
        _linkDetails = event.toString(); // Update UI with deep link
      });
    });
  }

  Future<void> createLink() async {
    String link;
    String? shortId;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      if (txtController.text.trim().isNotEmpty) {
        shortId = txtController.text.trim();
      }
      var data = await _appsonairFlutterApplinkPlugin.createAppLink(
        appLinkParams: AppLinkParams(
          url: 'https://appsonair.com',
          name: 'AppsOnAir',
          urlPrefix: 'YOUR_DOMAIN_NAME', //shouldn't contain http or https
          shortId: shortId, // If not set, it will be auto-generated
          socialMeta: SocialMeta(
            title: 'link title',
            description: 'link description',
            imageUrl: 'https://image.png',
          ),
          androidFallbackUrl: 'https://play.google.com',
          iosFallbackUrl: 'https://appstore.com',
          isOpenInAndroidApp: true,
          isOpenInBrowserAndroid: false,
          isOpenInIosApp: true,
          isOpenInBrowserApple: false,
        ),
      );
      link = data.toString();
      txtController.clear();
    } on PlatformException {
      link = 'Failed to create link.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _linkDetails = link;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter AppLink Example'),
          centerTitle: true,
        ),
        body: Padding(
          padding: const EdgeInsets.all(12),
          child: Column(
            children: [
              const SizedBox(height: 40),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: TextField(
                  controller: txtController,
                  decoration: const InputDecoration(
                      hintText: "Enter short link id if needed",
                      border: OutlineInputBorder()),
                ),
              ),
              const SizedBox(height: 20),
              Center(
                child: TextButton(
                  style: ButtonStyle(
                      backgroundColor:
                          WidgetStateProperty.all<Color>(Colors.greenAccent)),
                  onPressed: () {
                    createLink();
                  },
                  child: const Text("Create AppLink"),
                ),
              ),
              const SizedBox(height: 10),
              Center(
                child: TextButton(
                  style: ButtonStyle(
                      backgroundColor:
                          WidgetStateProperty.all<Color>(Colors.tealAccent)),
                  onPressed: () async {
                    try {
                      var data = await _appsonairFlutterApplinkPlugin
                          .getReferralInfo();
                      setState(() {
                        _linkDetails = data.toString();
                      });
                    } on PlatformException catch (e) {
                      log(e.toString());
                    }
                  },
                  child: const Text("Get Referral Link"),
                ),
              ),
              const SizedBox(height: 40),
              Flexible(
                child: Text(
                  _linkDetails,
                  textAlign: TextAlign.center,
                ),
              ),
              const SizedBox(height: 50)
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
152
downloads

Publisher

verified publisherappsonair.com

Weekly Downloads

The AppsOnAir AppLink Flutter SDK enables deep link tracking and engagement analytics for both iOS and Android. It serves as a powerful alternative to Firebase Dynamic Links.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on appsonair_flutter_applink

Packages that implement appsonair_flutter_applink