smartlinks_analytics 2.0.1
smartlinks_analytics: ^2.0.1 copied to clipboard
Dart analytics and deep linking API for the SmartLinks Flutter SDK.
example/lib/main.dart
// ignore_for_file: deprecated_member_use
import 'package:flutter/material.dart';
import 'package:smartlinks_analytics/smartlinks_analytics.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final analytics = SmartLinksAnalytics();
await analytics.initialize(apiKey: 'api-key');
analytics.getLink((DeepLinkRoute route) {});
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SmartLinks Analytics Example',
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SmartLinks Analytics')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () =>
SmartLinksAnalytics().sendEvent('example_open', null),
child: const Text('Send Event'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
final link = await SmartLinksAnalytics().generateLink(
route: '/home',
);
if (link != null && context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Generated: $link')));
}
},
child: const Text('Generate Link'),
),
],
),
),
);
}
}