medyas / flutter_qiblah

Flutter Qiblah is a plugin that allows you to display Qiblah direction in you app with support for both Android and iOS.
https://pub.dev/packages/flutter_qiblah
MIT License
127 stars 91 forks source link

Compass Not Moving - Compass sensor is unreliable, device calibration is needed. #46

Open md-rifatkhan opened 4 months ago

md-rifatkhan commented 4 months ago

I got Compass sensor is unreliable, device calibration is needed.

import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_qiblah/flutter_qiblah.dart';
import 'package:flutter_svg/svg.dart';

class Qibla extends StatelessWidget {
  final _compassSvg = SvgPicture.asset('assets/qibla/compass.svg');
  final _needleSvg = SvgPicture.asset(
    'assets/qibla/needle.svg',
    fit: BoxFit.contain,
    height: 300,
    alignment: Alignment.center,
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder(
        stream: FlutterQiblah.qiblahStream,
        builder: (_, AsyncSnapshot<QiblahDirection> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator(),);
          }

          final qiblahDirection = snapshot.data;

          return Stack(
            alignment: Alignment.center,
            children: <Widget>[
              Transform.rotate(
                angle: ((qiblahDirection?.direction ?? 0) * (pi / 180) * -1),
                child: _compassSvg,
              ),
              Transform.rotate(
                angle: ((qiblahDirection?.qiblah ?? 0) * (pi / 180) * -1),
                alignment: Alignment.center,
                child: _needleSvg,
              ),
              Positioned(
                bottom: 8,
                child: Text("${qiblahDirection?.offset.toStringAsFixed(3)}°"),
              )
            ],
          );
        },
      ),
    );
  }
}
md-rifatkhan commented 4 months ago

and Text("${qiblahDirection?.offset.toStringAsFixed(3)}°"), value is null

Tried in two device

Obada-Maplit commented 3 months ago

Same Same , what is the solution ??

md-rifatkhan commented 3 months ago

Same Same , what is the solution ??

It seems that location is still required when senor is available,

Obada-Maplit commented 3 months ago

Same Same , what is the solution ??

It seems that location is still required when senor is available,

the location is enabled in app

medyas commented 2 months ago

@md-rifatkhan @Obada-Maplit the location is required for the plugin to function. please check the example project

Obada2020 commented 2 months ago

@medyas how are u medyas , i enabled the location in app , but this message still appear on put app near laptop or Magnetfelt that log error in cmd , this error Compass Not Moving - Compass sensor is unreliable, device calibration is needed.

i need only way to recive this message in dart , how to catch it , i need to show warning to user that should app far away from any device .

pls help

medyas commented 2 months ago

@Obada2020 the message is printed in native android by the flutter_compass plugin and currently not able to detect this in the qiblah plugin