Datasource Listeners
This example demonstrates how to register a listener all GemKit sensors on a live DataSource
. The UI provides buttons to trigger permission requests and attach the listeners.
How it works
- Requests location, camera, and other sensors permissions with
permission_handler
package. - Creates a live
DataSource
and registers a singleDataSourceListener
for everyDataType
. - Safely casts each incoming
SenseData
and prints structured logs.
Initial map screen
Device Sensors Data Page
Main App
Device Sensors Data Page
Permissions
This sample requests Location (When In Use + Always), Camera, and Body Sensors.
Required Permissions
To ensure this example functions correctly, the necessary permissions must be added to the project's Android and iOS configuration files:
- Android
- iOS
Add the following code to the android/app/src/main/AndroidManifest.xml
file, within the <manifest>
block:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND" />
This example uses the Permission Handler package. Be sure to follow the setup guide.
Add the following to ios/Runner/Info.plist
inside the <dict>
:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is needed for map localization and navigation</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location is needed for map localization and navigation</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Camera access is needed for video recording</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need microphone access to record audio.</string>
<key>NSMotionUsageDescription</key>
<string>We use motion sensors to read acceleration, rotation, and orientation.</string>
This example uses the Permission Handler package. Follow the official setup instructions. Add this to your ios/Podfile
:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'PERMISSION_LOCATION=1',
'PERMISSION_CAMERA=1',
'PERMISSION_MICROPHONE=1'
]
end
end
end