简体   繁体   English

Flutter Web - 手机上的白屏/空白页 iOS 版本的 Z2567A5EC9705EB7AC2C98403DE06

[英]Flutter Web - white screen / blank page on mobile iOS version of web application

Currently developing a web app with Flutter web.目前正在使用 Flutter web 开发 web 应用程序。 Building, running and accessing the Firebase hosted application works fine when I'm on my laptop or Android device, however when I try to visit the application on a mobile iOS device I get a blank screen.当我在笔记本电脑或 Android 设备上时,构建、运行和访问 Firebase 托管应用程序工作正常,但是当我尝试在移动 iOS 设备上访问应用程序时,我得到一个空白屏幕I have tested this with several devices and they all show the same blank page.我已经用几种设备对此进行了测试,它们都显示相同的空白页。 In order to find the culprit I have tried the following:为了找到罪魁祸首,我尝试了以下方法:

  • Building and deploying with channels master / dev / beta使用通道 master / dev / beta 构建和部署
  • Adding and omitting canvas and/or --release to the build using flutter build web --web-renderer canvaskit --release使用flutter build web --web-renderer canvaskit --release添加和省略 canvas 和/或 --release 到构建
  • Cleaning my project along with deleting all generated code using flutter clean && find lib -maxdepth 20 -type f \( -name \"*.freezed.dart\" -o -name \"*.g.dart\" -o -name \"*.chopper.dart\" \) -delete使用flutter clean && find lib -maxdepth 20 -type f \( -name \"*.freezed.dart\" -o -name \"*.g.dart\" -o -name \"*.chopper.dart\" \) -delete清理我的项目并删除所有生成的代码flutter clean && find lib -maxdepth 20 -type f \( -name \"*.freezed.dart\" -o -name \"*.g.dart\" -o -name \"*.chopper.dart\" \) -delete
  • Changing <base href="/"> to <base href="./"> in my index.html在我的 index.html 中将<base href="/">更改为<base href="./">
  • Updating the first iOS meta tag to <meta name="mobile-web-app-capable" content="yes"> in my index.html将我的 index.html 中的第一个 iOS 元标记更新为<meta name="mobile-web-app-capable" content="yes">
  • Searching StackOverflow and Flutter issues for similar issues with no result在 StackOverflow 和 Flutter 问题中搜索类似问题但没有结果
  • Cleaning my cache and trying different phones清理我的缓存并尝试不同的手机

Edit: Safari on desktop also seems to cause a white screen (!)编辑:桌面上的 Safari 似乎也导致白屏(!)

My pubspec.yaml :我的pubspec.yaml

name: X
description: X

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.1.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # Firebase
  firebase_core: ^1.0.2
  cloud_firestore: ^1.0.3
  firebase_auth: ^1.0.1

  # Stacked
  stacked: ^2.0.2

  # Data
  freezed: ^0.14.1+2
  freezed_annotation: ^0.14.1
  json_serializable: ^4.1.0

  # Util
  get: 4.1.1
  intl: ^0.17.0
  get_it: ^6.0.0
  url_strategy: ^0.2.0
  flutter_dotenv: ^4.0.0-nullsafety.0
  logger: ^1.0.0
  flutter_screenutil: ^5.0.0
  flutter_form_builder: ^6.0.0-nullsafety.1

  # Https
  chopper: 4.0.0-nullsafety.0

  # UI
  progress_indicators: ^1.0.0
  cupertino_icons: ^1.0.2
  overlay_support: ^1.2.1
  flutter_svg: ^0.21.0+1
  google_fonts: ^2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.12.2
  stacked_generator: ^0.3.3
  chopper_generator: 4.0.0-nullsafety.0

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - .env
    - icon/
    - svg/
    - font/

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
flutter_intl:
  enabled: true # Required. Must be set to true to activate the package. Default: false
  class_name: LocalizedStrings # Optional. Sets the name for the generated localization class. Default: S
  main_locale: en # Optional. Sets the main locale used for generating localization files. Provided value should consist of language code and optional script and country codes separated with underscore (e.g. 'en', 'en_GB', 'zh_Hans', 'zh_Hans_CN'). Default: en
  arb_dir: lib/l10n # Optional. Sets the directory of your ARB resource files. Provided value should be a valid path on your system. Default: lib/l10n
  output_dir: lib/generated # Optional. Sets the directory of generated localization files. Provided value should be a valid path on your system. Default: lib/generated
  use_deferred_loading: false # Optional. Must be set to true to generate localization code that is loaded with deferred loading. Default: false
#  localizely: # Optional settings if you use Localizely platform. Read more: https://localizely.com/flutter-localization-workflow
#    project_id: # Get it from the https://app.localizely.com/projects page.
#    branch: # Get it from the “Branches” page on the Localizely platform, in case branching is enabled and you want to use a non-main branch.
#    upload_overwrite: # Set to true if you want to overwrite translations with upload. Default: false
#    upload_as_reviewed: # Set to true if you want to mark uploaded translations as reviewed. Default: false
#    download_empty_as: # Set to empty|main|skip, to configure how empty translations should be exported from the Localizely platform. Default: empty
#    ota_enabled: # Set to true if you want to use Localizely Over-the-air functionality. Default: false

My flutter doctor :我的flutter doctor

[✓] Flutter (Channel dev, 2.2.0-10.1.pre, on Mac OS X 10.15.7 19H524 darwin-x64, locale
    en-NL)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.1)
[✓] VS Code (version 1.55.2)
[✓] Connected device (1 available)
    ! Error: iPhone is not connected. Xcode will continue when iPhone is connected.
      (code -13)

• No issues found!

My index.html :我的index.html

<!DOCTYPE html>
<html>
<head>
    <base href="./">

    <meta charset="UTF-8">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">
    <meta name="description" content="X">

    <!-- iOS meta tags & icons -->
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="dashboard">
    <link rel="apple-touch-icon" href="icons/Icon-192.png">

    <!-- Favicon -->
    <link rel="icon" type="image/png" href="favicon.png"/>

    <title>X</title>
    <link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
     application. For more information, see:
     https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
    if ('serviceWorker' in navigator) {
        window.addEventListener('flutter-first-frame', function () {
            navigator.serviceWorker.register('flutter_service_worker.js?v=107771284');
        });
    }
</script>
<!--Firebase-->
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-auth.js"></script>
<script>
    var firebaseConfig = {
//
    };
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

What's causing this problem and how do I fix it?是什么导致了这个问题,我该如何解决?

Hosting flutter web app using Firebase Hosting CORRECT WAY使用 Firebase 托管flutter web 应用程序

https://youtu.be/-GAHjhBhXEc https://youtu.be/-GAHjhBhXEc

This video will help you to host your flutter web application on firebase hosting and will help to get rid of that blank white screen.该视频将帮助您在 firebase 主机上托管您的 flutter web 应用程序,并将有助于摆脱空白的白屏。

  1. build your web project in release mode by using command -使用命令在发布模式下构建您的 web 项目 -

flutter build web --release flutter 构建 web --release

  1. Now go to your project root folder -> go to build , now you will find folder named as web .现在 go 到您的项目根文件夹-> go构建,现在您将找到名为web的文件夹。 Now that's the folder that will be deployed for hosting.现在这是将部署用于托管的文件夹。

  2. Now you have to open your command prompt into your project root folder , you can also open your cmd in build folder but I suggest you to open in root folder so that you don't have to initialize firebase different functions again and again.现在您必须在项目根文件夹打开命令提示符,您也可以在构建文件夹中打开 cmd,但我建议您在根文件夹中打开,这样您就不必一次又一次地初始化 firebase 不同的功能。

  3. Now initialize firebase by using command -现在使用命令初始化 firebase -

firebase init firebase 初始化

  1. Now choose the firebase hosting option -> choose your project现在选择 firebase 托管选项 -> 选择您的项目

  2. Note this is the main step -- On asking 'what do you want to use as your public directory?'请注意,这是主要步骤——询问“您想将什么用作公共目录?”

what do you want to use as your public directory?你想用什么作为你的公共目录? (public) (上市)

just hit backspace and delete (public) and write build/web只需按退格键并删除(公共)并编写构建/网络

what do you want to use as your public directory?你想用什么作为你的公共目录? build/web构建/网络

then press enter然后按回车

  1. Now after two commands it will ask to overwrite your index.html another main step .现在,在两个命令之后,它会要求覆盖您的index.html另一个主要步骤

file web/index.html already exists.文件 web/index.html 已经存在。 Overwrite?y/n覆盖?y/n

just press n for No .只需按n即可 We don't want to overwrite that file我们不想覆盖那个文件

  1. Now after you firebase initialization successful completion write -现在你firebase初始化成功完成后写——

firebase deploy firebase 部署

And your project/webapp will run with no blank white screen:)并且您的项目/webapp 将在没有空白屏幕的情况下运行:)

A similar issue has been reported where the Flutter web page is blank in Safari.已经报告了一个类似的问题,其中 Flutter web 页面在 Safari 中为空白。 Possible cause of this issue is one of the plugins that's being used.此问题的可能原因是正在使用的插件之一。 You can isolate the cause of this issue by commenting out the plugins being used.您可以通过注释掉正在使用的插件来隔离此问题的原因。

Another path that you can also try is by upgrading the Flutter version that the Flutter app uses as well as the plugins being used.您也可以尝试的另一条路径是升级 Flutter 应用程序使用的 Flutter 版本以及正在使用的插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM