getTimeline method

  1. @override
Future<List<TimelineModel>> getTimeline({
  1. DateTime? startDate,
  2. DateTime? endDate,
  3. TimeZoneType timeZone = TimeZoneType.local,
})
override

Implementation

@override
Future<List<TimelineModel>> getTimeline({
  DateTime? startDate,
  DateTime? endDate,
  TimeZoneType timeZone = TimeZoneType.local,
}) async {
  final Map<String, dynamic> arguments = {
    'timeZone': timeZone.name.toLowerCase(), // Send enum as string
  };

  if (startDate != null) {
    arguments['startDate'] = startDate.millisecondsSinceEpoch;
  }

  if (endDate != null) {
    arguments['endDate'] = endDate.millisecondsSinceEpoch;
  }

  final result = await methodChannel.invokeMethod<List<dynamic>>(
    'getTimeline',
    arguments,
  );

  if (result == null) {
    return [];
  }

  // Convert the result to List<TimelineModel>
  return result.map((item) {
    if (item is Map) {
      return TimelineModel.fromMap(Map<String, dynamic>.from(item));
    }
    // Return empty TimelineModel if item is not a Map
    return const TimelineModel(stepCount: 0, timestamp: 0);
  }).toList();
}