Ad
Flutter - Activity Tracker App - Steps, Upstairs/downstairs, Stationary
I would like to use Flutter to create an app that tracks the user's current activity state - whether they are going up or down stairs, or if they are walking or stationary. The reason why I am using Flutter is because it needs to be integrated to an existing Flutter app, managed by another team.
I am new to software development. I would like to use the phone sensors: gyroscope, accelerometer and barometer. May I know where to start? E.g. useful packages and APIs, platform channels?
Ad
Answer
You can use package https://pub.dev/packages/sensors
example code https://github.com/flutter/plugins/blob/master/packages/sensors/example/lib/main.dart
code snippet
@override
Widget build(BuildContext context) {
final List<String> accelerometer =
_accelerometerValues?.map((double v) => v.toStringAsFixed(1))?.toList();
final List<String> gyroscope =
_gyroscopeValues?.map((double v) => v.toStringAsFixed(1))?.toList();
final List<String> userAccelerometer = _userAccelerometerValues
?.map((double v) => v.toStringAsFixed(1))
?.toList();
@override
void initState() {
super.initState();
_streamSubscriptions
.add(accelerometerEvents.listen((AccelerometerEvent event) {
setState(() {
_accelerometerValues = <double>[event.x, event.y, event.z];
});
}));
_streamSubscriptions.add(gyroscopeEvents.listen((GyroscopeEvent event) {
setState(() {
_gyroscopeValues = <double>[event.x, event.y, event.z];
});
}));
_streamSubscriptions
.add(userAccelerometerEvents.listen((UserAccelerometerEvent event) {
setState(() {
_userAccelerometerValues = <double>[event.x, event.y, event.z];
});
}));
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad