import 'package:flutter/material.dart';
import 'package:instalog_flutter/instalog_flutter.dart';
import 'package:instalog_platform_interface/instalog_platform_interface.dart';
void main() {
// Set up crash handling
Instalog.instance.crash.setup(
appRunner: () => runApp(const MyApp()),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
// Initialize with options
Instalog.instance.initialize(
apiKey: 'your_api_key_here',
options: const InstalogOptions(
isLogEnabled: true,
isLoggerEnabled: false,
isCrashEnabled: true,
isFeedbackEnabled: true,
),
);
// Identify the user
Instalog.instance.identifyUser(userId: 'user_${DateTime.now().millisecondsSinceEpoch}');
// Log app start event
Instalog.instance.logEvent(
event: 'app_started',
params: {
'timestamp': DateTime.now().toIso8601String(),
'version': '1.0.0',
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Instalog Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => Instalog.instance.showFeedbackModal(),
child: const Text('Show Feedback Modal'),
),
ElevatedButton(
onPressed: () {
try {
// Simulate an error
throw Exception('Test exception');
} catch (error, stack) {
Instalog.instance.sendCrash(error, stack);
}
},
child: const Text('Simulate & Report Error'),
),
],
),
),
);
}
}