前提・実現したいこと
FlutterでGeolocatorを仕様して位置情報を取得したいのですが、
iphone6s(実機)で実行するとビルド中にエラーを吐いてしまいます。
以下のサイトを参考にしました。
参考サイト
ご教授いただければと思います。
発生している問題・エラーメッセージ
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following assertion was thrown building Text("Location Infomation", inherit: true, size: 20.0): No Directionality widget found. RichText widgets require a Directionality widget ancestor. The specific widget that could not find a Directionality ancestor was: RichText softWrap: wrapping at box width maxLines: unlimited text: "Location Infomation" dirty The ownership chain for the affected widget is: "RichText ← Text ← Column ← Center ← FutureBuilder<GeolocationStatus> ← LocationSample ← [root]" Typically, the Directionality widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree. It determines the ambient reading direction and is used, for example, to determine how to lay out text, how to interpret "start" and "end" values, and to resolve EdgeInsetsDirectional, AlignmentDirectional, and other *Directional objects. The relevant error-causing widget was: Text file:///Users/tetetete/my_app2/lib/main.dart:54:17 When the exception was thrown, this was the stack: #0 debugCheckHasDirectionality.<anonymous closure> (package:flutter/src/widgets/debug.dart:247:7) #1 debugCheckHasDirectionality (package:flutter/src/widgets/debug.dart:263:4) #2 RichText.createRenderObject (package:flutter/src/widgets/basic.dart:5161:37) #3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5370:28) #4 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5947:11) ... ════════════════════════════════════════════════════════════════════════════════════════════════════ ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ No Directionality widget found. The relevant error-causing widget was: Text file:///Users/tetetete/my_app2/lib/main.dart:58:17
該当のソースコード
dart
1import 'package:flutter/material.dart'; 2import 'package:geolocator/geolocator.dart'; 3 4void main() { 5 runApp(LocationSample()); 6} 7 8class LocationSample extends StatefulWidget { 9 10 _LocationSampleState createState() => _LocationSampleState(); 11} 12 13class _LocationSampleState extends State<LocationSample> { 14 // Location 15 Position position; // Geolocator 16 17 18 void initState() { 19 super.initState(); 20 _getLocation(context); 21 } 22 23 Future<void> _getLocation(context) async { 24 Position _currentPosition = await Geolocator().getCurrentPosition( 25 desiredAccuracy: LocationAccuracy.high); // ここで精度を「high」に指定している 26 print(_currentPosition); 27 setState(() { 28 position = _currentPosition; 29 }); 30 } 31 32 33 Widget build(BuildContext context) { 34 return FutureBuilder<GeolocationStatus>( 35 future: Geolocator().checkGeolocationPermissionStatus(), 36 builder: 37 (BuildContext context, AsyncSnapshot<GeolocationStatus> snapshot) { 38 if (!snapshot.hasData) { 39 return const Center(child: CircularProgressIndicator()); 40 } 41 42 if (snapshot.data == GeolocationStatus.denied) { 43 return Text( 44 'Access to location denied', 45 textAlign: TextAlign.center, 46 ); 47 } 48 49 return Center( 50 child: Column( 51 mainAxisAlignment: MainAxisAlignment.center, 52 crossAxisAlignment: CrossAxisAlignment.center, 53 children: <Widget>[ 54 Text( 55 "Location Infomation", 56 style: TextStyle(fontSize: 20.0), 57 textDirection: TextDirection.ltr, 58 ), 59 Text("Your Current Location is :"), 60 Text("${position}") 61 ], 62 ), 63 ); 64 }); 65 } 66} 67
pubspec.yamの追記部分を抜粋
dependencies: flutter: sdk: flutter firebase_core: ^0.3.0 cloud_firestore: ^0.9.5 geolocator: ^5.1.3
info.plistの追記部分を抜粋
<key>NSLocationAlwaysUsageDescription</key> <string>Your location is required for this app</string> <key>NSLocationWhenInUseUsageDescription</key> <string>Your location is required for this app</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Your location is required for this app</string>
補足情報(FW/ツールのバージョンなど)
Flutter 1.18.0-9.0.pre.73
Dart 2.9.0
xcode 11.5 beta
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/10 08:28