queryEvents method

  1. @override
Future<List<EventUsageInfo>> queryEvents(
  1. DateTime startDate,
  2. DateTime endDate
)
override

Queries events within a specified date range.

Takes start and end dates as parameters and returns a Future that resolves to a list of EventUsageInfo objects.

Implementation

@override
Future<List<EventUsageInfo>> queryEvents(
    DateTime startDate, DateTime endDate) async {
  // Convert start and end dates to milliseconds since epoch.
  int end = endDate.millisecondsSinceEpoch;
  int start = startDate.millisecondsSinceEpoch;

  // Prepare a map of the start and end times to send to the native method.
  Map<String, int> interval = {'start': start, 'end': end};

  // Call the native method and await the result.
  List events = await methodChannel.invokeMethod('queryEvents', interval);

  // Map the result to a list of EventUsageInfo objects.
  List<EventUsageInfo> result =
      events.map((item) => EventUsageInfo.fromMap(item)).toList();
  return result;
}