activityStream method

  1. @override
Stream<ActivityData> activityStream()
override

Stream of activity data

Implementation

@override
Stream<ActivityData> activityStream() =>
    _eventChannel.receiveBroadcastStream().map((event) {
      try {
        final map = Map<String, dynamic>.from(event);
        final data = ActivityData.fromMap(map);

        if (kDebugMode) {
          print('Received event: $data');
        }

        return data;
      } catch (e) {
        if (kDebugMode) {
          print('Error mapping event: ${e.toString()}');
        }
        return ActivityData(
            timestamp: DateTime.now(), activity: ActivityType.unknown.name);
      }
    });