getGyroscopeData method

  1. @override
Future<GyroscopeData?> getGyroscopeData()
override

Get the current gyroscope data

Implementation

@override
Future<GyroscopeData?> getGyroscopeData() async {
  try {
    final subscription = gyroscopeEventStream().listen((event) {});
    await Future.delayed(const Duration(milliseconds: 100));
    final event = await gyroscopeEventStream().first;
    subscription.cancel();

    return GyroscopeData(
      x: event.x,
      y: event.y,
      z: event.z,
      timestamp: DateTime.now(),
    );
  } catch (e) {
    return null;
  }
}