概述

#

FlutterViewController 屬性 splashScreenView 已從 非空 更改為 可空

splashScreenView 的舊宣告

objc
@property(strong, nonatomic) UIView* splashScreenView;

splashScreenView 的新宣告

objc
@property(strong, nonatomic, nullable) UIView* splashScreenView;

背景

#

在此更改之前,在 iOS 上,當未設定啟動螢幕檢視時,splashScreenView 屬性會返回 nil,並且將該屬性設定為 nil 會移除啟動螢幕檢視。但是,splashScreenView API 被錯誤地標記為 非空。此屬性在 iOS add-to-app 場景中過渡到 Flutter 檢視時最為常用。

變更說明

#

雖然在 Objective-C 中可以透過將 splashScreenView 設定為 nil UIView 來規避不正確的 非空 註釋,但在 Swift 中這會導致編譯錯誤。

error build: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'

PR #34743 將屬性屬性更新為 可空。它現在可以在 Objective-C 和 Swift 中返回 nil,並且可以設定為 nil 來移除檢視。

遷移指南

#

如果 splashScreenView 在 Swift 中儲存在 UIView 變數中,請將其更新為可選型別 UIView?

遷移前的程式碼

swift
  var splashScreenView = UIView()
  var flutterEngine = FlutterEngine(name: "my flutter engine")
  let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
  splashScreenView = flutterViewController.splashScreenView // compilation error: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'

遷移後的程式碼

swift
  var splashScreenView : UIView? = UIView()
  var flutterEngine = FlutterEngine(name: "my flutter engine")
  let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
  let splashScreenView = flutterViewController.splashScreenView // compiles successfully
  if let splashScreenView = splashScreenView {
  }

時間線

#

穩定版釋出於: 3.7

參考資料

#

相關 PR