amplitude_session_replay 0.1.0-beta.1
amplitude_session_replay: ^0.1.0-beta.1 copied to clipboard
Session Replay SDK for Flutter.
example/lib/main.dart
import 'dart:io';
import 'package:amplitude_session_replay/amplitude_session_replay.dart';
import 'package:flutter/material.dart';
const _apiKey = 'YOUR_AMPLITUDE_API_KEY';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final deviceId =
Platform.isIOS
? 'flutter-ios-test-device'
: 'flutter-android-test-device';
final sessionId = DateTime.now().millisecondsSinceEpoch;
final sessionReplay = SessionReplay(
SessionReplayConfig(
apiKey: _apiKey,
deviceId: deviceId,
sessionId: sessionId,
sampleRate: 1.0,
logLevel: LogLevel.debug,
),
);
// You can set the sessionId or deviceId after construction but before recording starts.
await sessionReplay.setSessionId(sessionId);
runApp(SessionReplayWidget(sessionReplay: sessionReplay, app: const MyApp()));
// later in the code - start the session replay
await sessionReplay.start();
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Session Replay Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Session Replay'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _currentValue = 0;
void _incrementCounter() {
setState(() {
_currentValue++;
});
}
@override
Widget build(BuildContext context) {
return Semantics(
identifier: 'home_screen',
child: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Counter:'),
Text(
'$_currentValue',
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 24),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
),
);
}
}