I’ve spent the past year knowing about “How to use access Sensor in Flutter” and “how to use JAVA/KOTLIN with flutter” … i always what in to try that.
So here i am today using it Flutter and Kotlin to get the value of Pressure Sensor of the device.
I will break down step by step what i did and what i Learned:
- create Flutter project
- go to “android” Folder in your main flutter project , Right-click , and “open with Android Studio”
- we will write the code in Kotlin so don’t worry if you don’t know much about it
- we declare variable for method_channel_Name using (val==final)
- now we’re gonna create a function called setupChannels() : will return yes or false for the availability of pressure sensor
we will use SensorManager you can read more about it here
https://developer.android.com/reference/android/hardware/SensorManager
- call the setup channels on the main function in KOTLIN which is : configureFlutterEngine (will be overrided)
- create a function for destrying the method channel and call it in “ondestroy()”
- search more about some functionallity and data type in Kotlin