Skip to content

Commit ea5da04

Browse files
authored
Merge pull request #1289 from carp-dk:spm-agb-updates
Add support for iOS light sensor and update dependencies
2 parents 6389e7e + 3f57fb5 commit ea5da04

37 files changed

Lines changed: 1295 additions & 490 deletions

packages/light/.gitignore

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Miscellaneous
2+
*.class
3+
*.lock
4+
*.log
5+
*.pyc
6+
*.swp
7+
.DS_Store
8+
.atom/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.build/
13+
.swiftpm/
14+
build/
15+
16+
# IntelliJ related
17+
*.iml
18+
*.ipr
19+
*.iws
20+
.idea/
21+
22+
# Visual Studio Code related
23+
.classpath
24+
.project
25+
.settings/
26+
.vscode/
27+
28+
# Flutter repo-specific
29+
/bin/cache/
30+
/bin/internal/bootstrap.bat
31+
/bin/internal/bootstrap.sh
32+
/bin/mingit/
33+
/dev/benchmarks/mega_gallery/
34+
/dev/bots/.recipe_deps
35+
/dev/bots/android_tools/
36+
/dev/devicelab/ABresults*.json
37+
/dev/docs/doc/
38+
/dev/docs/flutter.docs.zip
39+
/dev/docs/lib/
40+
/dev/docs/pubspec.yaml
41+
/dev/integration_tests/**/xcuserdata
42+
/dev/integration_tests/**/Pods
43+
/packages/flutter/coverage/
44+
version
45+
analysis_benchmark.json
46+
47+
# packages file containing multi-root paths
48+
.packages.generated
49+
50+
# Flutter/Dart/Pub related
51+
**/doc/api/
52+
.dart_tool/
53+
.flutter-plugins
54+
.flutter-plugins-dependencies
55+
**/generated_plugin_registrant.dart
56+
.packages
57+
.pub-cache/
58+
.pub/
59+
build/
60+
flutter_*.png
61+
linked_*.ds
62+
unlinked.ds
63+
unlinked_spec.ds
64+
65+
# Android related
66+
**/android/**/gradle-wrapper.jar
67+
.gradle/
68+
**/android/captures/
69+
**/android/gradlew
70+
**/android/gradlew.bat
71+
**/android/local.properties
72+
**/android/**/GeneratedPluginRegistrant.java
73+
**/android/key.properties
74+
*.jks
75+
76+
# iOS/XCode related
77+
**/ios/**/*.mode1v3
78+
**/ios/**/*.mode2v3
79+
**/ios/**/*.moved-aside
80+
**/ios/**/*.pbxuser
81+
**/ios/**/*.perspectivev3
82+
**/ios/**/*sync/
83+
**/ios/**/.sconsign.dblite
84+
**/ios/**/.tags*
85+
**/ios/**/.vagrant/
86+
**/ios/**/DerivedData/
87+
**/ios/**/Icon?
88+
**/ios/**/Pods/
89+
**/ios/**/.symlinks/
90+
**/ios/**/profile
91+
**/ios/**/xcuserdata
92+
**/ioa/**/.build
93+
**/ios/.generated/
94+
**/ios/Flutter/.last_build_id
95+
**/ios/Flutter/App.framework
96+
**/ios/Flutter/Flutter.framework
97+
**/ios/Flutter/Flutter.podspec
98+
**/ios/Flutter/Generated.xcconfig
99+
**/ios/Flutter/ephemeral
100+
**/ios/Flutter/app.flx
101+
**/ios/Flutter/app.zip
102+
**/ios/Flutter/flutter_assets/
103+
**/ios/Flutter/flutter_export_environment.sh
104+
**/ios/ServiceDefinitions.json
105+
**/ios/Runner/GeneratedPluginRegistrant.*
106+
107+
# macOS
108+
**/macos/Flutter/GeneratedPluginRegistrant.swift
109+
**/macos/Flutter/ephemeral
110+
111+
# Coverage
112+
coverage/
113+
114+
# Symbols
115+
app.*.symbols
116+
117+
# Exceptions to above rules.
118+
!**/ios/**/default.mode1v3
119+
!**/ios/**/default.mode2v3
120+
!**/ios/**/default.pbxuser
121+
!**/ios/**/default.perspectivev3
122+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
123+
!/dev/ci/**/Gemfile.lock
124+
125+
.sdkmanrc
126+
**/.cxx/
127+
.zed/settings.json
128+
android/bin

packages/light/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 5.0.0
2+
3+
* Update Gradle and Kotlin
4+
* Added support for iOS Ambient reading - Requires specific permissions and certificates (see [Apple Docs | Configuring for SensorKit](https://developer.apple.com/documentation/sensorkit/configuring-your-project-for-sensor-reading))
5+
16
## 4.1.1
27

38
* upgrading ios version

packages/light/README.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,67 @@
22

33
[![pub package](https://img.shields.io/pub/v/light.svg)](https://pub.dartlang.org/packages/light)
44

5-
A Flutter plugin for collecting ambient light data from the [Android Environment Sensors](https://developer.android.com/develop/sensors-and-location/sensors/sensors_environment).
5+
A Flutter plugin for collecting ambient light data on Android and iOS.
6+
7+
Android uses the [Environment Sensors API](https://developer.android.com/develop/sensors-and-location/sensors/sensors_environment).
8+
iOS uses [SensorKit ambient light sensor](https://developer.apple.com/documentation/sensorkit/srsensor/ambientlightsensor).
69

710
## Install
811

9-
Add `light` as a dependency in the `pubspec.yaml` file.
12+
Add `light` as a dependency in `pubspec.yaml`.
1013

11-
For help on adding as a dependency, view the [documentation](https://flutter.io/using-packages/).
14+
## iOS requirements
1215

13-
## Usage
16+
> [!CAUTION]
17+
> Not all devices have SensorKit. Requires iOS 14 or higher. Reading sensory data from iOS requires research entitlements and previous approval from Apple for reading sensory data. Please see the documentations at [Configuring your project for sensor reading](https://developer.apple.com/documentation/sensorkit/configuring-your-project-for-sensor-reading).
18+
19+
SensorKit requires more setup than Android.
20+
21+
1. Enable the SensorKit entitlement and include ambient light in your app entitlements:
22+
23+
```xml
24+
<key>com.apple.developer.sensorkit.reader.allow</key>
25+
<array>
26+
<string>ambient-light-sensor</string>
27+
</array>
28+
```
29+
30+
SensorKit access is entitlement-gated by Apple. Without approved entitlement provisioning, iOS returns an invalid-entitlement error.
31+
32+
2. Add SensorKit purpose text in `Info.plist`:
33+
34+
```xml
35+
<key>NSSensorKitUsageDetail</key>
36+
<dict>
37+
<key>SRSensorUsageAmbientLightSensor</key>
38+
<string>Explain why your app needs ambient light sensor data.</string>
39+
</dict>
40+
```
1441

15-
Use the singleton `Light()` to listen on the `lightSensorStream` stream.
42+
3. Request authorization before or while starting the stream:
1643

1744
```dart
18-
StreamSubscription<int>? _lightEvents;
19-
20-
void startListening() {
21-
try {
22-
_lightEvents =
23-
Light().lightSensorStream.listen((luxValue) => setState(() {
24-
// Do something with the lux value
25-
}));
26-
} catch (exception) {
27-
print(exception);
28-
}
29-
}
30-
31-
void stopListening() {
32-
_lightEvents?.cancel();
33-
}
45+
final LightAuthorizationStatus status =
46+
await Light().requestAuthorization();
47+
```
48+
49+
On Android, `requestAuthorization()` returns `LightAuthorizationStatus.unavailable` and no runtime permission prompt is required.
50+
51+
If iOS setup is incomplete, the stream emits a `PlatformException` (for example, missing entitlement or usage description).
52+
53+
## Usage
54+
55+
```dart
56+
StreamSubscription<int>? _lightEvents;
57+
58+
Future<void> startListening() async {
59+
await Light().requestAuthorization(); // no-op on Android
60+
_lightEvents = Light().lightSensorStream.listen((int luxValue) {
61+
// Do something with lux.
62+
});
63+
}
64+
65+
void stopListening() {
66+
_lightEvents?.cancel();
67+
}
3468
```

packages/light/android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ group = "dk.cachet.light"
22
version = "1.0-SNAPSHOT"
33

44
buildscript {
5-
ext.kotlin_version = "1.8.22"
5+
ext.kotlin_version = "2.2.20"
66
repositories {
77
google()
88
mavenCentral()
99
}
1010

1111
dependencies {
12-
classpath("com.android.tools.build:gradle:8.1.0")
12+
classpath("com.android.tools.build:gradle:8.12.1")
1313
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
1414
}
1515
}
@@ -35,7 +35,7 @@ android {
3535
}
3636

3737
kotlinOptions {
38-
jvmTarget = JavaVersion.VERSION_11
38+
jvmTarget = "11"
3939
}
4040

4141
sourceSets {
@@ -47,7 +47,7 @@ android {
4747
minSdk = 21
4848
}
4949

50-
def flutterRoot = {
50+
dependencies {
5151
testImplementation("org.jetbrains.kotlin:kotlin-test")
5252
testImplementation("org.mockito:mockito-core:5.0.0")
5353
}

packages/light/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

packages/light/example/.idea/libraries/Dart_SDK.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/light/example/.idea/libraries/Flutter_for_Android.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/light/example/.idea/modules.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/light/example/.idea/runConfigurations/main_dart.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/light/example/.idea/workspace.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)