pulse_sdk_flutter 0.1.8
pulse_sdk_flutter: ^0.1.8 copied to clipboard
Pulse is a bug reporting and in-app feedback tool that allows developers to collect detailed user feedback and crash reports to improve their mobile apps. We offer a free tier for non-commerical usage [...]
example/lib/main.dart
// dart
import 'package:flutter/material.dart';
import 'package:pulse_sdk_flutter/pulse.dart';
import 'package:pulse_sdk_flutter/l10n/pulse_localizations.dart';
final Pulse pulse = Pulse(
"112979704528074466706",
"26bec0d8-50b5-410f-ae27-2e84348a85f4"
);
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: pulse.navigatorKey,
localizationsDelegates: PulseLocalizations.localizationsDelegates,
supportedLocales: PulseLocalizations.supportedLocales,
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _pulseContextSet = false;
bool _pulseInitialized = false;
int _counter = 0;
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!_pulseContextSet) {
// safe: context and Localizations are available here
_pulseContextSet = true;
// Set session properties
Pulse.setSessionProperty("user", "John Smith");
Pulse.setSessionProperty("version", "1.0.0");
// Initialize Pulse once context is set. Supports both sync and async init().
try {
final initResult = pulse.init();
if (initResult is Future) {
initResult.then((_) {
if (mounted) setState(() => _pulseInitialized = true);
}).catchError((e) {
debugPrint('Pulse init error: $e');
});
}
} catch (e) {
debugPrint('Pulse init exception: $e');
}
}
}
void _incrementCounter() {
setState(() {
_counter++;
});
// Run after the frame so Localizations and the widget tree are ready
WidgetsBinding.instance.addPostFrameCallback((_) {
debugPrint('About to call pulse.trigger(), navigatorKey.currentContext: ${pulse.navigatorKey.currentContext}');
pulse.trigger(); // now safe to call methods that use BuildContext
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(PulseLocalizations.of(context).appTitle)),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Counter: $_counter'),
if (!_pulseInitialized) const Padding(
padding: EdgeInsets.only(top: 8.0),
child: Text('Initializing Pulse...'),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
child: const Icon(Icons.add),
),
);
}
}