搜索插件、代码仓与 APP 分类

插件详情v1.0.1

compassx

Flutter 指南针插件,提供真实航向、精度和校准需求。

AndroidiOS
近 30 天下载
2130
喜欢数
20
Pub 分数
150

安装插件

flutter pub add compassx

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

CompassX 是一个 Flutter 插件,可提供对设备指南针数据的访问,包括真实航向、磁性精度和校准状态。它支持 Android 和 iOS 平台,通过设备传感器实时提供方向信息。该插件非常适合需要精确方向输入的导航、地图和增强现实应用。通过 `flutter pub add compassx` 进行简单设置,开发者即可将可靠的指南针功能集成到其应用中。源代码在 GitHub 上公开,便于透明化和自定义。

适合场景

  • 导航应用
  • 增强现实体验
  • 户外活动追踪
  • 基于地图的应用程序
  • 方向性UI元素

主要特点

  • 真航向支持
  • 磁性精度报告
  • 实时传感器更新
  • 校准状态监控
  • 跨平台兼容性

适合对象

  • 开发导航工具的开发者
  • 需要方向意识的应用程序
  • AR 和基于位置的服务
  • 需要传感器集成的移动应用

使用建议

  • 需要带有磁力计的设备
  • 准确性取决于环境
  • 可能需要用户校准
  • 某些设备上的后台操作受到限制
  • iOS 需要隐私权限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

CompassX

Logo

Provides reliable compass data and extensive documentation.

Usage

StreamBuilder<CompassXEvent>(
  stream: CompassX.events,
  builder: (context, snapshot) {
    if (!snapshot.hasData) return const Text('No data');
    final compass = snapshot.data!;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text('Heading: ${compass.heading}'),
        Text('Accuracy: ${compass.accuracy}'),
        Text('Should calibrate: ${compass.shouldCalibrate}'),
        Transform.rotate(
          angle: compass.heading * math.pi / 180,
          child: Icon(
            Icons.arrow_upward_rounded,
            size: MediaQuery.of(context).size.width - 80,
          ),
        ),
      ],
    );
  },
),
  • heading: The heading relative to true north in degree.
  • accuracy: The accuracy of the sensor data.
  • shouldCalibrate: Whether the sensor should be calibrated or not.

Install

$ flutter pub add compassx

Check the minimum supported version of your project and update as necessary.

  • iOS: 12
  • Android: 21

Request permission to get true heading in Android. Not required on iOS.

$ flutter pub add permission_handler

Specify the permissions one or both of the following in AndroidManifest.xml. It can be copied from example.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  • ACCESS_COARSE_LOCATION: Used when normal accuracy is required.
  • ACCESS_FINE_LOCATION: Used when the highest quality accuracy is required.

Add code to request permissions.

if (Platform.isAndroid) await Permission.location.request();

CompassX heading currently supports only portrait mode. It is recommended to fix the orientation of the device.

SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);

Testing

It is recommended to use a real device. iOS simulators cannot use the heading sensor (compass). See Testing CompassX for details.

Documentation

If you are going to use this plugin in your product apps, I strongly suggest you read full documentation carefully.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。