light 0.1.1 copy "light: ^0.1.1" to clipboard
light: ^0.1.1 copied to clipboard

outdated

A Flutter plugin for probing data from the light sensor using a platform channel. Works for Android only, since the light sensor API is not available on iOS.

light #

A light sensor plugin for Flutter, reads the light intensity registered by the light sensor (in [Lux]), and reports this number back via a stream. The API for getting the light exposure is only available on Android devices, and the plugin will therefore not work for iOS devices.

Install #

Add light as a dependency in pubspec.yaml. For help on adding as a dependency, view the documentation.

Usage #

All incoming data points are streamed with a StreamSubscription which is set up by calling the listen() method on the light.lightSensorStream stream object.

Given a method _onData(int lux) the subscription can be set up as follows:

Light _light;
StreamSubscription _subscription;
...
void onData(int luxValue) async {
    print("Lux value from Light Sensor: $luxValue");
}

void startListening() {
    _light = new Light();
    try {
      _subscription = _light.lightSensorStream.listen(onData);
    }
    on LightException catch (exception) {
      print(exception);
    }
}

The stream can also be cancelled again by calling the cancel() method:

  void stopListening() {
    _subscription.cancel();
  }
22
likes
40
pub points
86%
popularity

Publisher

verified publishercachet.dk

A Flutter plugin for probing data from the light sensor using a platform channel. Works for Android only, since the light sensor API is not available on iOS.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on light