Fix the camera resume model for a call screen
Your task
An AI wrote a Flutter video call screen that sets up the camera and the call once, in initState. When the app went to the background during a phone call and came back, the preview stayed black. The fix observes app lifecycle changes and sets the camera up again on resume. Your team replays lifecycle logs and counts how often the user comes back to a black preview.
An assistant wrote count_black_preview_resumes(lifecycle_events, observes_lifecycle), the replay. It is in the editor. It has a bug. Find it and fix it.
Input and output:
lifecycle_events: the log, in order.insertedis the screen's first build, which sets up the camera.pausedmeans the app went to the background and the system took the camera back.resumedmeans the app came back.disposedmeans the screen closed.observes_lifecycle: the screen handles lifecycle changes and sets the camera up again on resume.- Return how many resumes found a black preview.
Rules the tests check:
inserted: the screen is open and the camera is live.disposed: the screen is closed and the camera is not live.- While the screen is closed, ignore every other event. Ignore any event name not listed above.
paused: the camera is no longer live.resumedwith a live camera: nothing happens.resumedwithout a live camera: ifobserves_lifecycleis true, the camera is set up again and is live. Otherwise count one black preview, and the camera stays dark.
Examples
count_black_preview_resumes(lifecycle_events: list[str], observes_lifecycle: bool) -> intExample 1
Input
count_black_preview_resumes(["inserted", "paused", "resumed"], False)Output
1Example 2
Input
count_black_preview_resumes(["inserted", "paused", "resumed"], True)Output
0Example 3
Input
count_black_preview_resumes(["inserted", "paused", "resumed", "paused", "resumed"], False)Output
2