-3

Essentially, I would like to use a hand waving in from the proximity sensor to initiate a function. I'm not sure where to begin, so I thought this was the appropriate channel to pose the question and gain some insight. Thank you.

diegoveloper
  • 93,875
  • 20
  • 236
  • 194
Alex East
  • 145
  • 1
  • 2
  • 9

2 Answers2

2

Flutter has a proximity_plugin which actually listens to the proximity events.

Example:

// Modify the pubspec to add proximity_plugin
dependencies:
  proximity_plugin: "^1.0.0"

then

// First import the plugin
import 'package:proximity_plugin/proximity_plugin.dart';

// Add a listener to the events
proximityEvents.listen((ProximityEvent event) {
    // do something based on proximity change events
});

Hope that helped!

Hemanth Raj
  • 32,555
  • 10
  • 92
  • 82
2

Base on your application I hope you might need to retrieve all sensor data from the device. It is better to have to implement your code to get accelerometer, gyroscope, and proximity data. So, from one package you cover your all sensor requirements to the application. Maintaining is easy. The code is more readable so far...

Flutter has a solution to that also,

Before that, don't forget to add the hardware permission for WAVE_LOCK by,

<uses-permission android:name="android.permission.WAKE_LOCK" />

After that, You have to do is, add the library via dependency

//add to this in you pubspec.yaml file
dependencies:
  all_sensors: ^0.2.3

This is the latest package provided by flutter sometimes it may upgrade from time to time. make sure to upgrade it with your application.

Then add it to your application by importing it.

// in your dart file 
import 'package:all_sensors/all_sensors.dart';

Now implement your app the way you want.

Sahan Dissanayaka
  • 591
  • 2
  • 8
  • 26