import 'package:flutter/services.dart'; import 'dart:io'; class MotionService { static const MethodChannel _channel = MethodChannel('net.sumasen.gifunavi/motion'); static Future startMotionUpdates() async { if (Platform.isIOS) { try { await _channel.invokeMethod('startMotionUpdates'); } on PlatformException catch (e) { print("Failed to start motion updates: '${e.message}'."); } } else{ // Android の場合は何もしない、またはAndroid向けの代替実装を行う print("Motion updates not supported on this platform"); } } Future _handleMotionData(MethodCall call) async { switch (call.method) { case 'onMotionData': final Map motionData = call.arguments; // ここでモーションデータを処理します print('Received motion data: $motionData'); // 例: データを状態管理システムに渡す、UIを更新する等 break; default: print('Unknown method ${call.method}'); } } static Future stopMotionUpdates() async { if (Platform.isIOS) { try { await _channel.invokeMethod('stopMotionUpdates'); } on PlatformException catch (e) { print("Failed to stop motion updates: '${e.message}'."); } } } }