getStates method
Fetches the list of all Malaysian states and their corresponding zones.
Corresponds to the /v2/negeri
endpoint.
Returns a Future<List<State>>
upon success.
Throws WaktuSolatApiException on failure.
Implementation
Future<List<State>> getStates() async {
final response = await _getRequest('/v2/negeri');
if (response is List) {
try {
return response
.map((stateJson) =>
State.fromJson(stateJson as Map<String, dynamic>))
.toList();
} catch (e) {
// Handle potential parsing errors within the list
throw WaktuSolatApiException('Failed to parse states list: $e');
}
} else {
// Handle unexpected response format
throw WaktuSolatApiException(
'Unexpected response format received for /v2/negeri. Expected a List.');
}
}