import 'package:flutter/material.dart';
import 'package:synheart_core/synheart_core.dart';
class HumanStateMonitor extends StatefulWidget {
@override
_HumanStateMonitorState createState() => _HumanStateMonitorState();
}
class _HumanStateMonitorState extends State<HumanStateMonitor> {
HumanStateVector? _currentHSV;
FocusState? _currentFocus;
EmotionState? _currentEmotion;
bool _isInitialized = false;
@override
void initState() {
super.initState();
_initializeSynheart();
}
Future<void> _initializeSynheart() async {
try {
// Initialize Core SDK
await Synheart.initialize(
userId: 'user_123',
config: SynheartConfig(
enableWear: true,
enablePhone: true,
enableBehavior: true,
),
);
// Enable interpretation modules
await Synheart.enableFocus();
await Synheart.enableEmotion();
// Subscribe to updates
Synheart.onHSVUpdate.listen((hsv) {
setState(() => _currentHSV = hsv);
});
Synheart.onFocusUpdate.listen((focus) {
setState(() => _currentFocus = focus);
});
Synheart.onEmotionUpdate.listen((emotion) {
setState(() => _currentEmotion = emotion);
});
setState(() => _isInitialized = true);
} catch (e) {
print('Initialization error: $e');
}
}
@override
void dispose() {
Synheart.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!_isInitialized) {
return Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
return Scaffold(
appBar: AppBar(title: Text('Human State Monitor')),
body: ListView(
padding: EdgeInsets.all(16),
children: [
// HSV State
Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('HSV State', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 8),
if (_currentHSV != null) ...[
Text('Arousal: ${(_currentHSV!.meta.axes.affect.arousalIndex ?? 0).toStringAsFixed(2)}'),
Text('Valence Stability: ${(_currentHSV!.meta.axes.affect.valenceStability ?? 0).toStringAsFixed(2)}'),
Text('Engagement: ${(_currentHSV!.meta.axes.engagement.engagementStability ?? 0).toStringAsFixed(2)}'),
Text('Window: ${_currentHSV!.meta.embedding.windowType}'),
] else
Text('Waiting for data...'),
],
),
),
),
SizedBox(height: 16),
// Focus State
Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Focus', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 8),
if (_currentFocus != null) ...[
Text('Score: ${(_currentFocus!.score ?? 0).toStringAsFixed(2)}'),
Text('Cognitive Load: ${(_currentFocus!.cognitiveLoad ?? 0).toStringAsFixed(2)}'),
Text('Clarity: ${(_currentFocus!.clarity ?? 0).toStringAsFixed(2)}'),
LinearProgressIndicator(value: _currentFocus!.score ?? 0),
] else
Text('Waiting for data...'),
],
),
),
),
SizedBox(height: 16),
// Emotion State
Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Emotion', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 8),
if (_currentEmotion != null) ...[
Text('Stress: ${(_currentEmotion!.stress ?? 0).toStringAsFixed(2)}'),
Text('Calm: ${(_currentEmotion!.calm ?? 0).toStringAsFixed(2)}'),
Text('Engagement: ${(_currentEmotion!.engagement ?? 0).toStringAsFixed(2)}'),
Text('Valence: ${(_currentEmotion!.valence ?? 0).toStringAsFixed(2)}'),
] else
Text('Waiting for data...'),
],
),
),
),
],
),
);
}
}