hindsight_flutter 0.9.8
hindsight_flutter: ^0.9.8 copied to clipboard
Session replay for Flutter tree/state-delta capture with compact scene-graph encoding.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:hindsight_flutter/hindsight_flutter.dart';
const HindsightConfig _exampleConfig = HindsightConfig(
ingestUrl: 'http://127.0.0.1:8787',
projectId: 'hindsight-example',
apiKey: 'hs_example_local_key',
flushInterval: Duration(days: 1),
captureMetrics: false,
);
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hindsight.init(_exampleConfig);
runApp(const HindsightExampleApp());
}
/// Minimal runnable app showing Hindsight initialization and widget capture.
class HindsightExampleApp extends StatelessWidget {
/// Creates the minimal Hindsight example app.
const HindsightExampleApp({super.key, this.client});
/// Optional client override used by the smoke test.
final HindsightClient? client;
@override
Widget build(BuildContext context) {
return HindsightWidget(
client: client,
child: MaterialApp(
title: 'Hindsight Flutter example',
navigatorObservers: client == null
? <NavigatorObserver>[Hindsight.navigatorObserver]
: <NavigatorObserver>[client!.navigatorObserver],
home: const _ExampleHome(),
),
);
}
}
class _ExampleHome extends StatefulWidget {
const _ExampleHome();
@override
State<_ExampleHome> createState() => _ExampleHomeState();
}
class _ExampleHomeState extends State<_ExampleHome> {
int _interactions = 0;
bool _redactDetails = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Hindsight Flutter example')),
body: ListView(
padding: const EdgeInsets.all(24),
children: <Widget>[
Text(
'Interactions: $_interactions',
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 16),
FilledButton(onPressed: _recordTap, child: const Text('Tap event')),
const SizedBox(height: 24),
SwitchListTile(
title: const Text('Redact account details'),
value: _redactDetails,
onChanged: (value) {
setState(() {
_redactDetails = value;
});
HindsightWidget.maybeOf(context)?.addEvent(
'example_redaction_changed',
<String, Object?>{'redact': value},
);
},
),
HindsightPrivacyScope(
redactText: _redactDetails,
child: const ListTile(
title: Text('Customer: Ada Lovelace'),
subtitle: Text('Plan: Enterprise'),
),
),
],
),
);
}
void _recordTap() {
final next = _interactions + 1;
setState(() {
_interactions = next;
});
HindsightWidget.maybeOf(
context,
)?.addEvent('example_tap', <String, Object?>{'count': next});
}
}