使用带有Google Maps的两个屏幕返回到App的问题

Mar*_*ein 5 flutter google-maps-flutter

flutte谷歌地图似乎是一个更严重的错误。是#25653的副本

8月8日更新:当前进展:

试图用Sukhi修复该错误,但他无法重现该错误。我的同事们都可以复制它,但是无法修复它:P。还有其他人设法复制它吗?

用我的代码创建了一个github存储库,并更新了“到目前为止我尝试过的”

8月5日更新,进一步解决了实际问题

问题说明:

我的问题仅发生在调试发布的真实设备(而非模拟器)上的IO上。

我的确使用带有某些标记的google Maps小部件。轻按“标记”会打开另一个屏幕,其中包含更多信息,另一个Google Maps小部件以及通过URL启动器进行导航的可能性。(我将屏幕缩小为仅显示导致问题的小部件)

从该屏幕离开应用程序(例如,点击开始导航或转到IOs主屏幕),然后返回该应用程序会导致问题。

如果我再次返回到应用程序主屏幕,则仅显示白色屏幕。

加成:

将Google Maps Widget包装在Flex Widget(列或行)的信息屏幕中,甚至会导致更糟的行为。返回到Apps HomeScreen时,Flex窗口小部件的其他内容(例如带有文本的容器)将保持可见。

到目前为止,我尝试使它起作用但不起作用的方法是:

  1. 发布模式=>相同问题
  2. 禁用的导航过渡(像这样
  3. 异步等待网址启动
  4. 基于IO 12.3和12.4
  5. 在Future Builder中构建Maps窗口小部件

重现步骤:

  1. 安装google_maps_flutter 0.5.20 + 1url_launcher:5.0.3(我知道它不是最新的,但是那不是问题)

  2. 在不稳定的项目中复制CodeSnippet并在IO上构建。

  3. 点击标记

  4. 点击按钮“开始导航”或退出应用
  5. 在左上角的Apple Maps中点击以重定向到该应用程序或重新打开该应用程序
  6. 在信息屏幕中返回,点击左上角的左箭头
  7. 仅白屏可见

码:

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      initialRoute: "/",
      routes: {
        "/": (context) => HomePage(),
      },
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GoogleMap(
        initialCameraPosition: CameraPosition(
          target: const LatLng(47.6, 8.8796),
          zoom: 7,
        ),
        markers: Set<Marker>()
          ..add(
            Marker(
              markerId: MarkerId('hi'),
              position: LatLng(47.6, 8.8796),
              consumeTapEvents: true,
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => InfoScreen()),
                );
              },
            ),
          ),
      ),
    );
  }
}

class InfoScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("info Page"),),
      body: GoogleMap(
        initialCameraPosition: CameraPosition(
          target: const LatLng(47.6, 8.8796),
          zoom: 7,
        ),
        markers: Set<Marker>()
          ..add(
            Marker(
              markerId: MarkerId('hi2'),
              consumeTapEvents: true,
              position: LatLng(47.6, 8.8796),
              onTap: () {
                if (Platform.isIOS) {
                  launch('https://maps.apple.com/?q=47.6,8.8796');
                } else {
                  launch(
                      'https://www.google.com/maps/search/?api=1&query=47.6,8.8796');
                }
              },
            ),
          ),
      ),
      bottomNavigationBar: BottomAppBar(
        elevation: 0,
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 19, horizontal: 25),
          height: 80,
          child: InkWell(
            onTap: () {
              if (Platform.isIOS) {
                launch('https://maps.apple.com/?q=47.6,8.8796');
              } else {
                launch(
                    'https://www.google.com/maps/search/?api=1&query=47.6,8.8796');
              }
            },
            child: Text(
              'START NAVIGATION',
              style: TextStyle(
                letterSpacing: 0.35,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Run Code Online (Sandbox Code Playgroud)

扑医生:

dynClient36:flutter_app mhein$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.5 18F132, locale de-DE)

[?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[?] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[?] iOS tools - develop for iOS devices
[?] Android Studio (version 3.4)
[?] VS Code (version 1.36.1)
[?] Connected device (2 available)

• No issues found!
dynClient36:flutter_app mhein$ 

Run Code Online (Sandbox Code Playgroud)
info plist

<?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>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</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>flutter_app</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>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>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>JELEJÖLWEKQÖEwkÖ</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Always Permission</string>
    <key>io.flutter.embedded_views_preview</key>
    <true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

小智 2

我可以在 iPhone 6 上重现该问题。通过 Xcode 启动时,它实际上抛出了此错误:Thread 1: EXC_BAD_ACCESS (code=1, address=0x1)在 Runner/Runner/Supporting Files/main.m 中。

等待 url 在 onTap 函数中启动后,如下所示:

onTap: () async {
  if (Platform.isIOS) {
    await launch('https://maps.apple.com/?q=47.6,8.8796');
  } else {
    await launch('https://www.google.com/maps/search/?api=1&query=47.6,8.8796');
  }
}   
Run Code Online (Sandbox Code Playgroud)

我无法再次重现该错误。我猜想当未等待 url 启动时,Flutter 应用程序无法正确进入后台模式。