Fix the next step for a location request
Your task
An AI wrote a Flutter "find nearby" feature that called requestPermission(), ignored the result, and went straight to getCurrentPosition(). On a phone where location was already allowed, it worked. After a tester denied the prompt, or with location switched off, the feature hung or crashed. The fix turns the permission result into one next step.
An assistant wrote resolve_location_request(permission_status, service_enabled, has_shown_rationale). It is in the editor. It has a bug. Find it and fix it.
Input and output:
permission_status: the status the permission API returned.service_enabled: location services are on at the operating system level.has_shown_rationale: the app has already explained once why it needs location.- Return the next step:
fetch,request_permission,show_rationale,open_app_settings,open_location_settingsorunsupported.
Rules the tests check. Return the first that applies:
- The status is not exactly one of
notDetermined,denied,deniedForever,restricted,whileInUseoralways, case included:unsupported. deniedForeverorrestricted:open_app_settings, since the app can never ask again.- Location services are off:
open_location_settings. whileInUseoralways:fetch. This is the only step that reads the position.notDetermined:request_permission.denied:request_permissionif the rationale has been shown, otherwiseshow_rationale.
Examples
resolve_location_request(permission_status: str, service_enabled: bool, has_shown_rationale: bool) -> strExample 1
Input
resolve_location_request("whileInUse", True, False)Output
"fetch"Example 2
Input
resolve_location_request("denied", True, False)Output
"show_rationale"Example 3
Input
resolve_location_request("deniedForever", True, True)Output
"open_app_settings"