StepRecordStore class

Local store for step records using SQLite

This service provides a Health Connect-like API for storing and querying step data with support for real-time streams, aggregation, and filtering.

For low-end devices, enable background isolate mode to prevent UI blocking:

final store = StepRecordStore(useIsolate: true);

Example:

final store = StepRecordStore();
await store.initialize();

// Write a record
await store.insertRecord(StepRecord(
  stepCount: 100,
  fromTime: startTime,
  toTime: endTime,
  source: StepRecordSource.foreground,
));

// Read total steps
final total = await store.readTotalSteps();

// Watch for real-time updates
store.watchTotalSteps().listen((total) => print('Total: $total'));

Constructors

StepRecordStore({bool useIsolate = false})
Creates a new StepRecordStore

Properties

hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Whether the store has been initialized
no setter
isUsingIsolate bool
Whether this store is using background isolate mode
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() Future<void>
Close the store
deleteAllRecords() Future<void>
Delete all step records
deleteRecordsBefore(DateTime date) Future<void>
Delete records older than a specific date
getRecordCount() Future<int>
Get the number of records
getStats({DateTime? from, DateTime? to}) Future<Map<String, dynamic>>
Get step statistics for a date range
hasDuplicateRecord({required DateTime fromTime, required DateTime toTime, int? stepCount, StepRecordSource? source}) Future<bool>
Check for duplicate or overlapping records
hasOverlappingRecord({required DateTime fromTime, required DateTime toTime}) Future<bool>
Check for any overlapping records in a time range
initialize() Future<void>
Initialize the SQLite store
insertRecord(StepRecord record) Future<void>
Insert a new step record
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readRecords({DateTime? from, DateTime? to, StepRecordSource? source}) Future<List<StepRecord>>
Read all step records
readStepsBySource(StepRecordSource source, {DateTime? from, DateTime? to}) Future<int>
Read step count by source
readTotalSteps({DateTime? from, DateTime? to}) Future<int>
Read total step count (aggregate)
toString() String
A string representation of this object.
inherited
watchRecords({DateTime? from, DateTime? to, StepRecordSource? source}) Stream<List<StepRecord>>
Watch all step records in real-time
watchTotalSteps({DateTime? from, DateTime? to}) Stream<int>
Watch total step count in real-time

Operators

operator ==(Object other) bool
The equality operator.
inherited