lemnisk_flutter 1.1.6
lemnisk_flutter: ^1.1.6 copied to clipboard
The Lemnisk Flutter Plugin allows you to track user event data from your Android or IOS app. The Plugin can be easily imported into any Android or iOS app. Based on the data it receives from the user [...]
example/lib/main.dart
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// import 'package:firebase_core/firebase_core.dart';
// import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:lemnisk_flutter/flutter_wrapper_method_channel.dart';
// Import the separated pages
import 'notification_details_page.dart';
import 'button_screen.dart';
// Global navigator key to access navigator from anywhere
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
// Global initialization flag to prevent duplicate initialization
// bool _firebaseInitialized = false;
// Safe Firebase initialization that won't cause duplicate initialization errors
// Future<FirebaseApp> _initializeFirebase() async {
// if (_firebaseInitialized) {
// // Return the existing instance if already initialized
// return Firebase.app();
// }
// _firebaseInitialized = true;
// return await Firebase.initializeApp();
// }
void main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
// await _initializeFirebase();
runApp(MyApp());
} catch (e) {
print('Error initializing Firebase: $e');
runApp(MyApp());
}
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// Initialize method channel in the app's state
static const MethodChannel _channel = MethodChannel('com.example.lemnisk/notification_navigation');
@override
void initState() {
super.initState();
_setupMethodChannel();
}
void _setupMethodChannel() {
print('Setting up notification method channel');
_channel.setMethodCallHandler((call) async {
print('Received method call: ${call.method}');
// Handle notification navigation
if (call.method == 'navigateToNotificationPage') {
if (call.arguments == null) {
print('ERROR: Null arguments received');
return false;
}
try {
// Convert arguments to the right format
final arguments = Map<String, dynamic>.from(call.arguments);
// Navigate to notification details page
if (navigatorKey.currentState != null) {
navigatorKey.currentState!.pushNamed(
'/notification-details',
arguments: arguments,
);
return true;
} else {
print('ERROR: Navigator not available');
return false;
}
} catch (e) {
print('ERROR: Failed to handle notification: $e');
return false;
}
}
return null;
});
print('Method channel setup complete');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
routes: {
'/': (context) => MyButtonScreen(),
'/notification-details': (context) => NotificationDetailsPage(),
},
);
}
}