ambient_light

Creator: coderz1093

Last updated:

0 purchases

ambient_light Image
ambient_light Images

Languages

Categories

Add to Cart

Description:

ambient light

ambient_light #
A Flutter plugin to access ambient light sensor data on Android, iOS and macOS. This plugin allows
you to retrieve the current ambient light level and listen to continuous updates.
Features #

Android: Uses the SensorManager to access the device's ambient light sensor.


iOS: Uses CoreMotion to access the ambient light sensor data on compatible iOS devices.


macOS: Uses IOKit to access the ambient light sensor data on compatible macOS devices.
Retrieve Current Light Level: Get the current ambient light level as a single value.
Stream Light Level: Listen to continuous updates of the ambient light level.

Installation #
To use this plugin, add ambient_light as a dependency in your pubspec.yaml file.
Usage #
Import the package and use the provided methods to get ambient light sensor data.
import 'package:ambient_light/ambient_light.dart';

void main() async {
// Get ambient light value
double? lightLevel = await AmbientLight().currentAmbientLight();
print('Ambient light level: $lightLevel');

// Listen to ambient light sensor data stream
AmbientLight().ambientLightStream.listen((double lightLevel) {
print('Ambient light level: $lightLevel');
});
}

copied to clipboard
Note: checkout Example for complete explanation
Methods #
Future<double?> currentAmbientLight();
copied to clipboard
Returns the current ambient light level as a double. Returns null if the sensor is not available.
Stream<double> get ambientLightStream;
copied to clipboard
Returns a stream of ambient light sensor data as double.
iOS #
For iOS, the plugin uses CoreMotion to access ambient light sensor data. You need to add the
following key to your Info.plist to request access to the camera, which is required for measuring
ambient light.

<key>NSCameraUsageDescription</key><string>We need access to the camera to measure ambient light.
</string>

copied to clipboard
Contributions #
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
Licence #
This project is licensed under the MIT License. See
the LICENSE file for
details.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.