A Flutter plugin for collecting ambient light data from the Android Environment Sensors.
Add light
as a dependency in the pubspec.yaml
file.
For help on adding as a dependency, view the documentation.
Use the singleton Light()
to listen on the lightSensorStream
stream.
StreamSubscription<int>? _lightEvents;
void startListening() {
try {
_lightEvents =
Light().lightSensorStream.listen((luxValue) => setState(() {
// Do something with the lux value
}));
} catch (exception) {
print(exception);
}
}
void stopListening() {
_lightEvents?.cancel();
}