flutter / flutter/samples

[add-to-app] Cannot re-open Flutter screen after multiple transitions between iOS native and Flutter

Open
#2,654 3 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
Dart
Stars
19.3k
Forks
7.9k
Avg merge
3h 26m
Merged PRs (30d)
3

Description

## Steps to Reproduce

1. Launch the [fullscreen](https://github.com/flutter/samples/tree/main/add_to_app/fullscreen) app.
2. Tap "Launch Flutter ViewController" to open the Flutter screen.
3. Tap "Exit this screen" to close the Flutter screen.
4. Repeat steps 2 and 3.
5. 💥Tap "Launch Flutter ViewController", but the Flutter screen does not appear.

https://github.com/user-attachments/assets/9f3a406f-4380-4fb7-a633-222a19243fb6

## Environment

**Flutter**: 3.32.4
**Xcode**: 16.4
**iOS Simulator**: iPhone 16 (iOS 18.5)

## Additional Information

- The following message is logged when attempting to transition to the Flutter screen, even if the transition appears successful.
```
[ERROR:flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm(183)] The supplied FlutterEngine is already used with FlutterViewController instance . One instance of the FlutterEngine can only be attached to one FlutterViewController at a time. Set FlutterEngine.viewController to nil before attaching it to another FlutterViewController.
```
- Also appeared in the [plugin](https://github.com/flutter/samples/tree/main/add_to_app/plugin) app and an app built following the [official guide](https://docs.flutter.dev/add-to-app/ios/add-flutter-screen).
- The number of transitions before the issue appears varies.
- Not appeared in the [multiple_flutters](https://github.com/flutter/samples/tree/main/add_to_app/multiple_flutters) app.
- I think setting `flutterEngine.viewController = nil` on Flutter screen dismissal would solve the problem, but I don't know if this is the right or recommended solution.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.