cardio_flutter 1.0.1
cardio_flutter: ^1.0.1 copied to clipboard
Flutter package for Cardio SDK - measure heart rate, blood pressure, SpO2, respiratory rate, and HRV using your device camera.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:cardio_flutter/cardio_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Cardio Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF317796),
primary: const Color(0xFF317796),
brightness: Brightness.light,
),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _isLoading = false;
Future<void> _handleStartTest() async {
setState(() => _isLoading = true);
try {
const String organizationId = "your-org-id";
const String apiKey = "your-api-key";
final response = await http
.post(
Uri.parse(
'https://consumer-api.iselfietest.com/sdk/central/access-token',
),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'organizationId': organizationId,
'apikey': apiKey,
}),
)
.timeout(const Duration(seconds: 10));
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
if (data['success'] == true) {
final String accessToken = data['access_token'];
debugPrint('Fetched fresh access token: $accessToken');
if (!mounted) return;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CardioWebView(
accessToken: accessToken,
organizationId: organizationId,
appUserId: "user-123",
useAccessToken: true,
),
),
);
} else {
_showError('API Error: ${data['message'] ?? 'Failed to get token'}');
}
} else {
_showError('HTTP Error ${response.statusCode}: ${response.body}');
}
} catch (e) {
_showError('Network Error: ${e.toString()}');
} finally {
if (mounted) {
setState(() => _isLoading = false);
}
}
}
void _showError(String message) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message), backgroundColor: Colors.red),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Cardio Test',
style: TextStyle(color: Colors.white),
),
backgroundColor: const Color(0xFF317796),
iconTheme: const IconThemeData(color: Colors.white),
),
body: Container(
color: Colors.white,
child: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.favorite, size: 80, color: Color(0xFF317796)),
const SizedBox(height: 32),
const Text(
'Cardio Test',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Color(0xFF317796),
),
),
const SizedBox(height: 16),
const Text(
'Measure your heart rate, blood pressure,\nrespiratory rate, and blood oxygen levels\nusing just your camera',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16, color: Color(0xFF434651)),
),
const SizedBox(height: 48),
if (_isLoading)
const CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Color(0xFF317796),
),
)
else
ElevatedButton(
onPressed: _handleStartTest,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF317796),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 48,
vertical: 16,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'Start Cardio Test',
style: TextStyle(fontSize: 18),
),
),
const SizedBox(height: 32),
const Text(
'Note: This will fetch a fresh access token\nautomatically before starting the test.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
color: Color(0xFF434651),
fontStyle: FontStyle.italic,
),
),
],
),
),
),
),
);
}
}