// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:health/health.dart';
import 'package:flutter/services.dart';
Future<int> todaySteps() async {
// Define the types to get
List<HealthDataType> types = [HealthDataType.STEPS];
// Create an instance of HealthFactory
HealthFactory health = HealthFactory();
// Request authorization to access health data
bool requested = await health.requestAuthorization(types);
int totalSteps = 0;
if (requested) {
// Get today's date
DateTime now = DateTime.now();
DateTime start = DateTime(now.year, now.month, now.day);
DateTime end = now;
// Fetch the health data
try {
List<HealthDataPoint> healthData =
await health.getHealthDataFromTypes(start, end, types);
// Process the health data
for (HealthDataPoint point in healthData) {
if (point.type == HealthDataType.STEPS) {
totalSteps += (point.value as num).toInt();
}
}
} catch (e) {
print("Error retrieving health data: $e");
}
} else {
print("Authorization not granted");
}
return totalSteps;
}