搜尋套件、儲存庫與 APP 分類

套件詳情v0.2.1

ambient_light

一個強大的外掛程式,可在 Android、iOS 和 macOS 上存取環境光感測器資料

AndroidiOSmacOSWindowsLinux
近 30 天下載
1920
喜歡數
21
Pub 分數
160

安裝套件

flutter pub add ambient_light

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

ambient_light 套件提供了一種跨平台解決方案,可在 Android、iOS、macOS、Windows 和 Linux 上存取環境光感測器資料。它讓應用程式能夠偵測周圍光線水平,進而實現動態 UI 調整,例如自動亮度變更或適應性顯示設定。此外,該套件輕巧且與 Flutter 應用程式無縫整合,透過串流提供即時感測器更新。支援在可用情況下於前景與背景運作,非常適合節能且具備情境感知能力的應用程式。

適用情境

  • 自動亮度調節
  • 節能顯示模式
  • 上下文感知的使用者介面設計
  • 環境監測應用
  • 智慧照明整合

主要特色

  • 即時光照水平流
  • 跨平台支援(Android、iOS、macOS、Windows、Linux)
  • 簡單的 API,支援基於串流的更新
  • 低功耗
  • 背景傳感器存取

適合對象

  • 需要環境意識的應用程式
  • 無障礙功能
  • 電池優化工具
  • 智慧家庭整合
  • 可穿戴裝置和行動應用程式

使用建議

  • 傳感器可用性取決於設備硬體
  • 某些平台上的精度有限
  • 需要在 Android 和 iOS 上具備適當的權限
  • 並非所有舊設備都支援
  • 背景使用可能受到作業系統策略的限制

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.

所屬分類

依賴

依賴清單 1 項

  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案

暫無相關資料。