Fixes https://github.com/flutter/flutter/issues/138193. Was first attempted to fix in https://github.com/flutter/engine/pull/48096, but that was not reliable since it's all asynchronous. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style