搜索插件、代码仓与 APP 分类

GitHub 代码仓ali-you/ambient-light-plugin

环境光插件

ali-you/ambient-light-plugin open-source repository details.

环境光插件 项目封面
星标
3
复刻
5
最近推送(UTC)
2026年7月15日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Ambient Light for iOS and android

Issues Issues GitHub Pull Requests GitHub GitHub Repo stars

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, you can add it to your Flutter project in one of two ways:

1. Add to pubspec.yaml

Include the following dependency in your pubspec.yaml file:

dependencies:
  ambient_light: ^0.2.1
  
2. Add directly from the terminal

Run the following command to add the plugin directly to your project:

flutter pub add ambient_light

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 {
  final AmbientLight _ambientLight = AmbientLight(frontCamera: true);
  
  // 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');
  });
}

[!NOTE] Useful information that users should know, even when skimming content.

  • The frontCamera parameter is iOS only and allows you to specify whether to use the front or back camera for measuring ambient light. For other platforms, you can initialize with the default:
    final AmbientLight _ambientLight = AmbientLight();
    
  • Checkout Example for complete explanation

Methods

Future<double?> currentAmbientLight();

Returns the current ambient light level as a double. Returns null if the sensor is not available.

Stream<double> get ambientLightStream;

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>

Contributions

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

Licence

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

Ali Yousefi GitHub avatar
GitHub 作者

Ali Yousefi ↗

@mavan-innovative-studioMashhad, Iran
语言C++CMakeSwiftDartKotlinCRubyObjective-C

此仓库发布的插件

使用的依赖

依赖清单 5 项

  • flutter{"sdk":"flutter"}
  • flutter_web_plugins{"sdk":"flutter"}
  • plugin_platform_interface^2.0.2
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^5.0.0

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗