linksapp 0.1.2
linksapp: ^0.1.2 copied to clipboard
Flutter Universal Link and App Link handling for LinksApp.
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:linksapp/linksapp.dart';
const appKey = String.fromEnvironment(
'LINKSAPP_APP_KEY',
defaultValue: 'your-app-key',
);
void main() => runApp(const LinksAppExample());
class LinksAppExample extends StatelessWidget {
const LinksAppExample({super.key});
@override
Widget build(BuildContext context) =>
MaterialApp(title: 'LinksApp example', home: const LinkHome());
}
class LinkHome extends StatefulWidget {
const LinkHome({super.key});
@override
State<LinkHome> createState() => _LinkHomeState();
}
class _LinkHomeState extends State<LinkHome> {
late final LinksApp _links;
LinksAppResolution? _lastLink;
String? _error;
@override
void initState() {
super.initState();
_links = LinksApp(
appKey: appKey,
onResolved: (result) {
if (!mounted) return;
setState(() {
_lastLink = result;
_error = null;
});
// In a real app, route to result.deepLink with your own router.
// Pass result.ref along if you need the referral context.
},
onError: (error, stackTrace) {
if (!mounted) return;
setState(() => _error = error.toString());
},
);
unawaited(_links.start());
}
@override
void dispose() {
unawaited(_links.dispose());
super.dispose();
}
@override
Widget build(BuildContext context) {
final link = _lastLink;
return Scaffold(
appBar: AppBar(title: const Text('LinksApp example')),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('App key: $appKey'),
const SizedBox(height: 16),
if (_error != null) Text('Error: $_error'),
if (link == null && _error == null)
const Text('Waiting for a verified LinksApp URL…'),
if (link != null) ...[
Text('Code: ${link.code}'),
SelectableText('Destination: ${link.deepLink}'),
Text('Referral: ${link.ref ?? 'none'}'),
],
],
),
),
);
}
}