gyroscopeEvents property
A broadcast stream of events from the device gyroscope.
Implementation
@override
Stream<GyroscopeEvent> get gyroscopeEvents {
if (_gyroscopeEventStreamController == null) {
_gyroscopeEventStreamController = StreamController<GyroscopeEvent>();
_featureDetected(
() {
final gyroscope = html.Gyroscope();
setProperty(
gyroscope,
'onreading',
allowInterop(
(_) {
_gyroscopeEventStreamController!.add(
GyroscopeEvent(
gyroscope.x as double,
gyroscope.y as double,
gyroscope.z as double,
),
);
},
),
);
gyroscope.start();
gyroscope.onError.forEach(
(e) => developer.log(
'The gyroscope API is supported but something is wrong!',
error: e),
);
},
apiName: 'Gyroscope()',
permissionName: 'gyroscope',
onError: () {
_gyroscopeEventStreamController!.add(GyroscopeEvent(0, 0, 0));
},
);
_gyroscopeEventResultStream =
_gyroscopeEventStreamController!.stream.asBroadcastStream();
}
return _gyroscopeEventResultStream;
}