plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Question]: Sensors Plus: iPhone / Tablet Web Usage

Open Noah765 opened this issue 3 years ago • 0 comments

What is your question?

I want to use their plugin sensors_plus for a mobile web application, but it does not work. The events don't get callbacks and I would like to know if and what I could have done wrong. I tried it on an IPhone 6s, an iPhone X and an iPad (8th generation).

Debug console output (run in Chrome, on a windows pc):

[log] Magnetometer() is not supported by the User Agent.
[log] The accelerometer API is supported but something is wrong!
[log] The linear acceleration API is supported but something is wrong!
[log] The gyroscope API is supported but something is wrong!

Code:

String _location = "Unknown";
String _magnetometer = "Unknown";
String _gyroscope = "Unknown";
String _accelerometer = "Unknown";
String _userAccelerometer = "Unknown";

@override
void initState() {
  super.initState();

  MyLocation.getLocationStream().then((stream) => stream.listen(
      (position) => setState(() => _location = "${position.latitude}, ${position.longitude}")));

  accelerometerEvents
      .listen((event) => setState(() => _accelerometer = "${event.x}, ${event.y}, ${event.z}"));

  userAccelerometerEvents.listen(
      (event) => setState(() => _userAccelerometer = "${event.x}, ${event.y}, ${event.z}"));

  gyroscopeEvents
      .listen((event) => setState(() => _gyroscope = "${event.x}, ${event.y}, ${event.z}"));

  magnetometerEvents
      .listen((event) => setState(() => _magnetometer = "${event.x}, ${event.y}, ${event.z}"));
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Text("Location:"),
          Text(_location, style: Theme.of(context).textTheme.headline4),
          const Text("Magnetometer:"),
          Text(_magnetometer, style: Theme.of(context).textTheme.headline4),
          const Text("Gyroscope:"),
          Text(_gyroscope, style: Theme.of(context).textTheme.headline4),
          const Text("Accelerometer:"),
          Text(_accelerometer, style: Theme.of(context).textTheme.headline4),
          const Text("User Accelerometer:"),
          Text(_userAccelerometer, style: Theme.of(context).textTheme.headline4),
        ],
      ),
    ),
  );
}

I have already asked on stackoverflow and received no response.

Noah765 avatar Aug 12 '22 13:08 Noah765