Brazilian ZIP code (CEP) lookup library for Dart and Flutter, powered by ViaCEP.
- Accepts CEPs in any format (
01310-100,01310100,01.310-100) - JSON or XML output
- Null-safe, well tested
- Pure Dart — works on every platform
dependencies:
flutter_cep2: ^1.0.2dart pub getimport 'package:flutter_cep2/flutter_cep2.dart';
Future<void> main() async {
final cep = FlutterCep2();
try {
final result = await cep.search('01310-100');
print('${result.logradouro}, ${result.bairro} — ${result.localidade}/${result.uf}');
} on CepException catch (e) {
print('CEP error: ${e.message}');
} finally {
cep.dispose();
}
}await cep.search('01310-100', output: CepOutputFormat.xml);Creates the service. Accepts an optional http.Client (useful for tests).
Looks up the CEP. Throws CepException for invalid or not-found codes.
Closes the underlying HTTP client.
| Property | Type | Description |
|---|---|---|
cep |
String |
Postal code in XXXXX-XXX format |
logradouro |
String |
Street/road name |
complemento |
String? |
Extra address info |
bairro |
String |
Neighborhood |
localidade |
String |
City |
uf |
String |
State (SP, RJ, ...) |
unidade |
String? |
Postal unit |
ibge |
String |
IBGE municipality code |
gia |
String? |
GIA code (São Paulo) |
ddd |
String? |
Area code |
siaf |
String? |
SIAF code |
See CONTRIBUTING.md. Bug reports and PRs welcome.
MIT — see LICENSE.