簡體   English   中英

Flutter URL 啟動器 Google 地圖使應用程序崩潰

[英]Flutter URL launcher Google Maps crashes App

幾天前推出谷歌地圖和蘋果地圖都很好。 我在主頻道上將 Flutter 更新到最新版本到 1.13.1。 我假設更新后它停止工作。 所以我將頻道更改為測試版並嘗試過,但仍然無法正常工作。 當嘗試啟動谷歌地圖或蘋果地圖時,IOS 應用程序崩潰,我既不理解錯誤,也沒有在互聯網上找到任何東西。

任何幫助深表感謝。

我的用戶界面代碼:


ListTile(
                 title: Text("Launch Google Maps", textAlign: TextAlign.center),
                  onTap: () async {
                    final String clubName =
                        clubs[index].name.toString().replaceAll(" ", "+");
                    print("Name: $clubName"); // 'Flawless+Club'
                    final String clubCity = clubs[index].stadt;
                    print("Name: $clubCity"); // 'London'
                    final String newGoogleUrl =
                        "https://www.google.com/maps/dir/?api=1&destination=$clubName+$clubCity";

                    if (await canLaunch(newGoogleUrl)) {
                      await launch(newGoogleUrl);
                    } else {
                      throw 'Could not launch $newGoogleUrl';
                    }
                  },
                ),

顫振醫生 -v 輸出:

[✓] Flutter (Channel beta, v1.12.13+hotfix.3, on Mac OS X 10.15.1 19B88, locale en-DE)
    • Flutter version 1.12.13+hotfix.3 at /Library/Flutter
    • Framework revision 57f2df76d7 (2 days ago), 2019-12-05 21:23:21 -0800
    • Engine revision ac9391978e
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/murat/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2.1, Build version 11B500
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.40.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.0

[✓] Connected device (1 available)

• No issues found!

點擊 ListTile 時出錯:

Lost connection to device.
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50b97b20 objc_exception_throw + 48
    2   Foundation                          0x00007fff2578c55b -[__NSConcreteURLComponents initWithString:] + 0
    3   CoreServices                        0x00007fff24e970bd -[_LSURLOverride initWithOriginalURL:checkingForAvailableApplications:newsOnly:] + 151
    4   CoreServices                        0x00007fff24e97992 -[_LSURLOverride initWithOriginalURL:newsOnly:] + 25
    5   CoreServices                        0x00007fff24e982ae _ZN14LaunchServices12URLOverridesL20getURLOverrideCommonEP5NSURLb + 399
    6   CoreServices                        0x00007fff24e9810e -[LSApplicationWorkspace(LSURLOverride) URLOverrideForURL:] + 14
    7   UIKitCore<…>
Exited (sigterm)

根據我的經驗, onTap不能很好地與async關鍵字配合使用。 我會將邏輯提取到另一種方法中。 build方法甚至不應該在其中包含邏輯,它們應該僅用於 UI,因為它們運行起來應該很便宜,並且可以隨時出於任何原因調用。

onTap: () => myFunction(clubs, index),

// the function
void myFunction(var clubs, int index) async {
    final String clubName = clubs[index].name.toString().replaceAll(" ", "+");
    print("Name: $clubName"); // 'Flawless+Club'
    final String clubCity = clubs[index].stadt;
    print("Name: $clubCity"); // 'London'
    final String newGoogleUrl = "https://www.google.com/maps/dir/?api=1&destination=$clubName+$clubCity";

    if (await canLaunch(newGoogleUrl)) {
        await launch(newGoogleUrl);
    } else {
        throw 'Could not launch $newGoogleUrl';
    }
}

問題解決了。

我在我的club[index].stadt中有一個城市列表,一個帶有變音符號為“ä,ö,ü”的城市。

通過添加final String clubCity = clubs[index].stadt.toString().replaceAll("ü", "ue"); 它解決了這個問題。 因為,每當在 url 中調用帶有變音符號的城市時,它就會使應用程序崩潰!

天啊,這花了我很長時間!

我有同樣的錯誤。 我的問題是我正在使用這個包含航點名稱的 url。

'https://maps.apple.com/?q=' + '$name' + '&ll=$lat,$lon';

如果航點名稱 ( $name ) 包含空格,例如 'New York' launch_url不會將空格字符轉換為 %20。

我使用name.toString().replaceAll(' ', "%20")修復了它。 完整網址示例: https://maps.apple.com/?q=' + name.toString().replaceAll(' ', "%20") + '&ll=$lat,$lon' : https://maps.apple.com/?q=' + name.toString().replaceAll(' ', "%20") + '&ll=$lat,$lon'

我有完全相同的症狀,但我的問題出在&waypoints= URL 的一部分。 顯然 android 將能夠消化以下 URL(示例):

https://www.google.com/maps/dir/?api=1&origin=1.11,-0.123&destination=2.22,-0.456&waypoints=1.11,-0.123|1.67,-0.245|2.22,-0.456&travelmode=driving&dir_action=navigate

而對於 ios 版本,我必須顯式轉換| %7C waypoints內的標志,所以它看起來像這樣:

https://www.google.com/maps/dir/?api=1&origin=1.11,-0.123&destination=2.22,-0.456&waypoints=1.11,-0.123%7C1.67,-0.245%7C2.22,-0.456&travelmode=driving&dir_action=navigate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM