step_counter
Flutter plugin that acts as a Pedometer in ObjC and Java using HealthKit and the Google Fitness Store.
Usage
To use this plugin, add step_counter
as a dependency in your pubspec.yaml file.
Getting Started
Android
Enable Fitness API and obtain an OAuth 2.0 client ID.
iOS
Enable HealthKit and add NSHealthShareUsageDescription key to the Info.plist file.
Template
readAll() {
Future<String> stepCountToday = StepCounter.getStepsToday();
Future<String> stepCountInIntervales = StepCounter.getStepsInIntervals(int startTimeMilliseconds, int endTimeMilliseconds, int intervalQuantity, String intervalUnit);
Future<String> getStepsDuringTimePeriod = StepCounter.getStepsDuringTime(int startTimeMilliseconds, int endTimeMilliseconds);
}
Sample Usage
readAll() {
String results = "";
//Get today's date and set a date to the desired start date of the query.
var now = new DateTime.now();
var past = now.subtract(new Duration(hours: 12));
//Convert both dates to milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
int end = now.millisecondsSinceEpoch;
int start = past.millisecondsSinceEpoch;
//Set the length and unit of intervals to be queried within the range of dates previously defined. Current
//options are 'minutes', 'days', and 'hours'.
int intervalLength = 20;
String intervalUnit = 'minutes';
//Query HealthKit (on iOS) or the Google Fitness Store (on Android) through StepCounter.
//Get the total number of steps between the start and end date in intervals.
//Returns key-value pairs of the start of the interval in milliseconds since the "Unix epoch" and the total
//number of steps in that interval.
Future<String> stepCount = StepCounter.getStepsInIntervals(start, end, intervalLength, intervalUnit);
//Get the total number of steps between the start date and end date.
//Returns an int.
Future<int> stepCount = StepCounter.getStepsDuringTime(start, end);
//Get the total number of steps since midnight today.
//Returns an int.
Future<int> stepCount = StepCounter.getStepsToday();
}
Libraries
Dart
- dart:ui
- Built-in types and core primitives for a Flutter application. [...]
- dart:async
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- dart:collection
- Classes and utilities that supplement the collection support in dart:core. [...]
- dart:convert
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- dart:core
- Built-in types, collections, and other core functionality for every Dart program. [...]
- dart:developer
- Interact with developer tools such as the debugger and inspector. [...]
- dart:math
- Mathematical constants and functions, plus a random number generator. [...]
- dart:typed_data
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- dart:io
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- dart:isolate
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]