iOS FlutterViewController 的 splashScreenView 設為可為空值
摘要
#FlutterViewController
屬性 splashScreenView
已從 nonnull
變更為 nullable
。
splashScreenView
的舊宣告
objc
@property(strong, nonatomic) UIView* splashScreenView;
splashScreenView
的新宣告
objc
@property(strong, nonatomic, nullable) UIView* splashScreenView;
背景
#在此變更之前,在 iOS 上,當未設定啟動畫面檢視時,splashScreenView
屬性會傳回 nil
,並且將屬性設定為 nil
會移除啟動畫面檢視。但是,splashScreenView
API 被錯誤地標記為 nonnull
。此屬性最常用於在 iOS 新增至應用程式案例中轉換為 Flutter 檢視時。
變更描述
#雖然在 Objective-C 中可以透過將 splashScreenView
設定為 nil
的 UIView
來繞過不正確的 nonnull
註解,但在 Swift 中這樣做會導致編譯錯誤。
error build: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'
PR #34743 將屬性屬性更新為 nullable
。它在 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
除非另有說明,否則本網站上的文件反映了 Flutter 的最新穩定版本。頁面最後更新於 2024-04-04。 檢視原始碼 或 回報問題。