Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import androidx.annotation.Nullable;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.CountDownLatch;

public abstract class TestableFlutterActivity extends FlutterActivity {
private Object flutterUiRenderedLock = new Object();
private AtomicBoolean isScenarioReady = new AtomicBoolean(false);
private final CountDownLatch flutterUiRenderedLatch = new CountDownLatch(1);

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
Expand All @@ -40,22 +39,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}

protected void notifyFlutterRendered() {
synchronized (flutterUiRenderedLock) {
isScenarioReady.set(true);
flutterUiRenderedLock.notifyAll();
}
flutterUiRenderedLatch.countDown();
}

public void waitUntilFlutterRendered() {
try {
if (isScenarioReady.get()) {
return;
}
synchronized (flutterUiRenderedLock) {
flutterUiRenderedLock.wait();
}
// Reset the lock.
flutterUiRenderedLock = new Object();
flutterUiRenderedLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down