oguzhnatly / flutter_carplay

🚗 Apple CarPlay for Flutter Apps. Aims to make it safe to use apps made with Flutter in the car by integrating with CarPlay.
https://pub.dev/packages/flutter_carplay
MIT License
218 stars 63 forks source link

Blank Screen Appears for a Few Seconds on App Start with CarPlay #58

Open harpreetslabs opened 4 days ago

harpreetslabs commented 4 days ago

Description

When launching the app with CarPlay, a blank screen appears for a few seconds before the app fully initializes. This issue occurs even when following the documentation and running the official example project. It gives the impression that the app is resuming from an old state.


Steps to Reproduce

  1. Clone the official example project from the repository. (https://github.com/oguzhnatly/flutter_carplay)
  2. Build and run the app on a iOS simulator.
  3. Observe the app's behavior on startup:
    • First, an old activity is displayed.
    • Then, a black screen appears for some seconds.
    • Finally, the app initializes properly.

Expected Behavior

The app should initialize immediately without showing a blank screen or old activity.


Actual Behavior

The app displays an old activity followed by a black screen for a few seconds before initializing.


Screenshots/Video

https://github.com/user-attachments/assets/32ebd4af-ca3c-43e2-b411-2725908c8331


Code Samples

SceneDelegate.swift (Copied from example)

@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }
        window = UIWindow(windowScene: windowScene)
        let flutterEngine = FlutterEngine(name: "SceneDelegateEngine")
        flutterEngine.run()
        GeneratedPluginRegistrant.register(with: flutterEngine)
        let controller = FlutterViewController.init(engine: flutterEngine, nibName: nil, bundle: nil)
        window?.rootViewController = controller
        window?.makeKeyAndVisible()
    }
}

AppDelegate.swift (Copied from example)

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application( _ application: UIApplication,
                               didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        return true
    }
}

Environment

Package Version: 1.0.3 Flutter Version: 3.22.2 Minimum deployment version: 14.1 Device/Simulator: iOS simulator iPhone 14 pro

richanshah commented 15 hours ago
import UIKit
import Flutter

let flutterEngine = FlutterEngine(name: "SceneDelegateEngine")

@main
@objc class AppDelegate: FlutterAppDelegate, MessagingDelegate {

    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        // Start the FlutterEngine
        flutterEngine.run()

        // Attach the FlutterEngine to a FlutterViewController
        let controller = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
        window?.rootViewController = controller
        window?.makeKeyAndVisible()

        print("flutterEngine after")

        // Register plugins with the FlutterEngine
        GeneratedPluginRegistrant.register(with: flutterEngine)

        // Call super to complete the launch process
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

@harpreetslabs check this if it works for u