質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

Geolocation

Geolocation(ジオロケーション)は、携帯電話やインターネットに接続したコンピューターターミナルなど、オブジェクトの現実世界での地理的位置の情報を扱う技術であり、位置評価の実施や、実際に評価された位置を示す場合もあります。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

Q&A

解決済

1回答

3401閲覧

FlutterでGeolocatorを使用して位置情報を取得

takahiro00

総合スコア84

Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

Geolocation

Geolocation(ジオロケーション)は、携帯電話やインターネットに接続したコンピューターターミナルなど、オブジェクトの現実世界での地理的位置の情報を扱う技術であり、位置評価の実施や、実際に評価された位置を示す場合もあります。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

0グッド

1クリップ

投稿2020/05/05 07:06

編集2020/05/05 07:06

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エラーに「No Directionality widget found.」とあるので、以下のページと同じ原因のようです。
https://qiita.com/nichiyoshi/items/f63fff2a051f87bd58ad

以下のようにすべてのTextWidgetにtextDirectionを指定してみてください。

Dart

1 children: <Widget>[ 2 Text( 3 "Location Infomation", 4 style: TextStyle(fontSize: 20.0), 5 textDirection: TextDirection.ltr, 6 ), 7 Text( 8 "Your Current Location is :", 9 textDirection: TextDirection.ltr, 10 ), 11 Text( 12 "${position}", 13 textDirection: TextDirection.ltr, 14 ) 15 ],

投稿2020/05/08 10:52

satokei

総合スコア1204

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takahiro00

2020/05/10 08:28

上記で解決しました。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問