🛣️ViaCEP Request
Aqui vou demonstrar como foi feito a requisição de dados de endereço, através do CEP, utilizando a API ViaCep, seguindo a nossa arquitetura padrão.
import 'package:json_annotation/json_annotation.dart';
part "address.g.dart";
@JsonSerializable()
class Address {
@JsonKey(defaultValue: '')
final String? cep;
@JsonKey(defaultValue: '', name: "logradouro")
final String? street;
@JsonKey(defaultValue: '', name: "bairro")
final String? neighboor;
@JsonKey(defaultValue: '', name: "complemento")
final String? complement;
@JsonKey(defaultValue: '', name: "localidade")
final String? city;
@JsonKey(defaultValue: '', name: "uf")
final String? state;
Address({
this.cep,
this.street,
this.neighboor,
this.complement,
this.state,
this.city,
});
factory Address.fromJson(Map<String, dynamic> json) =>
_$AddressFromJson(json);
Map<String, dynamic> toJson() => _$AddressToJson(this);
}Last updated