I created a custom action on a page load to go fetch the step count for the last 24 hours using the Code Copilot. The code is below.
When I try to save my code, I get the error - The action is empty or cannot be parsed.
Any insight?
// Automatic FlutterFlow imports
import '/backend/supabase/supabase.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!
Future newCustomAction() async {
// Using the package health, access the Google Fit step count for the last 24 hours.
import 'package:health/health.dart';
Future<int> getStepCount() async {
// Define the time range for the query
DateTime endDate = DateTime.now();
DateTime startDate = endDate.subtract(Duration(hours: 24));
// Define the query parameters
HealthDataQuery query = HealthDataQuery(
dataType: HealthDataType.STEPS,
dateFrom: startDate,
dateTo: endDate,
);
// Request authorization to access health data
bool authorized = await Health.requestAuthorization();
if (authorized) {
// Retrieve the step count data
List<HealthDataPoint> results = await Health.getHealthDataFromType(query);
// Calculate the total step count
int stepCount = 0;
results.forEach((result) {
stepCount += result.value.toInt();
});
return stepCount;
} else {
throw Exception('Authorization not granted');
}}