import 'dart:async';

import 'package:flutter/material.dart';
import 'package:sensors_plus/sensors_plus.dart'; // Import the sensors package

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      debugShowCheckedModeBanner: false,
      home: SensorExample(),
    );
  }
}

class SensorExample extends StatefulWidget {
  @override
  _SensorExampleStats createState() => _SensorExampleStats();
}

class _SensorExampleStats extends State<SensorExample> {
  double _gyroX = 0.0;
  double _gyroY = 0.0;
  double _gyroZ = 0.0;

  double _accelX = 0.0;
  double _accelY = 0.0;
  double _accelZ = 0.0;

  double _barometerEvent = 0.0;

  double _magnX = 0.0;
  double _magnY = 0.0;
  double _magnZ = 0.0;
  @override
  void initState() {
    super.initState();

    barometerEventStream().listen((event) {
      setState(() {
        _barometerEvent = event.pressure;
      });
    });
    magnetometerEventStream().listen((event){
      setState(() {
        _magnX = event.x;
        _magnY = event.y;
        _magnZ = event.z;
      });
    });

    gyroscopeEventStream().listen((GyroscopeEvent event) {
      setState(() {
        _gyroX = event.x;
        _gyroY = event.y;
        _gyroZ = event.z;
      });
    });

    accelerometerEventStream().listen((event) {
      setState(() {
        _accelX = event.x;
        _accelY = event.y;
        _accelZ = event.z;
      });
    });
  }
  @override
  void dispose() {
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Sensor Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Gyroscope Data:'),
            Text('gryoX: ${_gyroX.toStringAsFixed(2)}'),
            Text('gyroY: ${_gyroY.toStringAsFixed(2)}'),
            Text('gryoZ: ${_gyroZ.toStringAsFixed(2)}'),

            Text('Accelerometer Data:'),
            Text('accelX: ${_accelX.toStringAsFixed((2))}'),
            Text('accelY: ${_accelY.toStringAsFixed((2))}'),
            Text('accelZ: ${_accelZ.toStringAsFixed((2))}'),

            Text('Barometer Data:'),
            Text('baroPressure: ${_barometerEvent.toStringAsFixed(2)}'),

            Text('Magnetometer Data:'),
            Text('magnX: ${_magnX.toStringAsFixed(2)}'),
            Text('magnY: ${_magnY.toStringAsFixed(2)}'),
            Text('magnZ: ${_magnZ.toStringAsFixed(2)}'),
          ],
        ),
      ),
    );
  }
}

flutter/dart에서 사용가능한 패키지 중 하나인 sensors_plus에 있는 가속도계, 기압계, 자이로스코프, 자력계를 화면에 표시하는 방법

info.plist에서 http 접근을 허용할 수 있으나 권장되지 않는 방법이라고 한다.

권장하는 방법은  특정 사이트만 허용하는 방법이라고 하므로 이에 대해 작성한다.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleDisplayName</key>
	<string>간편지연증명서 출력</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>traindelaycertificateapp</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>$(FLUTTER_BUILD_NAME)</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>$(FLUTTER_BUILD_NUMBER)</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIApplicationSupportsIndirectInputEvents</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>GADApplicationIdentifier</key>
	<string>your app admob id</string>
	
	<!-- 여기부터 ATS 설정 추가 -->
	<key>NSAppTransportSecurity</key>
	<dict>
		<!-- 전체적으로는 ATS 적용 (false: 임의 로드는 허용하지 않음) -->
		<key>NSAllowsArbitraryLoads</key>
		<false/>

		<!-- 예외 도메인들 -->
		<key>NSExceptionDomains</key>
		<dict>
			<!-- info.siteA.com 예외 설정 -->
			<key>info.siteA.com</key>
			<dict>
				<key>NSIncludesSubdomains</key>
				<true/>
				<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
				<true/>
			</dict>

			<!-- www.siteB.co.kr 예외 설정 -->
			<key>www.siteB.co.kr</key>
			<dict>
				<key>NSIncludesSubdomains</key>
				<true/>
				<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
				<true/>
			</dict>
		</dict>
	</dict>
</dict>
</plist>

'' 카테고리의 다른 글

플레이 콘솔 임시 버전 삭제 방법  (1) 2024.12.02


'Web' 카테고리의 다른 글

Nexacro Dataset CRUD 정리  (0) 2020.06.18
Nexacro Components 제어 Function  (0) 2020.06.18
Nexacro Div 정렬 Function  (0) 2020.06.18

+ Recent posts