首页 > 解决方案 > 使用谷歌地图的两个屏幕返回应用程序的问题

问题描述

似乎是flutte google maps的一个更严重的错误。与#25653重复

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

试图用 Sukhi 修复这个错误,但他无法重现这个错误。我的同事都能够重现它,但无法修复它:P。有没有其他人设法复制它?

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

8月5日更新,越来越接近真正的问题

问题说明:

我的问题仅发生在debugrelease上真实设备(不是模拟器)上的IO上。

我确实使用带有一些标记的谷歌地图小部件。点击标记会打开另一个屏幕,其中包含更多信息、另一个谷歌地图小部件以及通过 url 启动器导航的可能性。(我减少了屏幕只显示导致问题的小部件)

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

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

添加:

将 Google Maps Widget 包装在 Flex Widget(列或行)中的信息屏幕中甚至会导致更糟糕的行为。返回到应用程序主屏幕时,Flex Widget 的其他内容(例如带有文本的容器)将保持可见。

到目前为止我试图让它工作但没有工作:

  1. 发布模式 => 同样的问题
  2. 禁用导航转换(像这样
  3. 异步等待 url 启动
  4. 基于 IO 12.3 和 12.4
  5. 在 Future Builder 中构建地图小部件

重现步骤:

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

  2. 在 Flutter 项目中复制 CodeSnippet 并在 IO 上构建。

  3. 点击标记

  4. 点击按钮“开始导航”或离开应用程序
  5. 点击左上角的 Apple Maps 重定向到 App 或重新打开 App
  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,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

颤振医生:

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$ 

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>

标签: fluttergoogle-maps-flutter

解决方案


运行您的代码并通过在 info.plist 中添加以下键来解决问题

键名:io.flutter.embedded_views_preview 类型:布尔值:是

当我在 iPhone 5S 上运行代码时,我可以在开始时看到空白的白屏(因此,甚至没有显示 HomePage())。有一个错误,但它是:

[VERBOSE-2:platform_view_layer.cc(19)] Trying to embed a platform view but the PrerollContext does not support embedding

这导致Github 上与适用于 iOS 的 Google Maps 插件相关的问题。

PoC 在这里供您参考。


推荐阅读