title: Flutter NoSuchMethodError: The method '[]' was called on null. how to solve this error when giving get in an api using flutter
body: <p>I have a problem consuming an api via get method. Apparently the error is in the mapping of my model, but at least for me the model is ok. If someone can help me, I would be grateful.</p>
  <p>that's my method, i'm using get connect to access the api. _restClient refers to my base url.</p>
  <pre><code>class ActionPageRepositoryImpl implements ActionPageRepository {
    final RestClient _restClient;
  
    ActionPageRepositoryImpl({required RestClient restClient})
        : _restClient = restClient;
  
    @override
    Future&lt;ActionPageModel&gt; getActionPageJobs(int id) async {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  
      final String token = sharedPreferences.getString(&quot;token&quot;) ?? &quot;&quot;;
  
      final Response result =
          await _restClient.get&lt;ActionPageModel&gt;(&quot;/job_acoes/$id&quot;, headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer $token'
      }, decoder: (data) {
        if (data != null) {
          print(&quot;status codeData ${data}&quot;);
          return ActionPageModel.fromMap(data);
        }
        return ActionPageModel.fromMap(data);
      });
      if (result.hasError) {
        print(&quot;status codeError ${result.statusCode}&quot;);
        throw (&quot;erro ao buscar dados&quot;);
      }
  
      print(&quot;status codeBody ${result.body}&quot;);
      print(&quot;Status codeSucess ${result.statusCode}&quot;);
  
      return result.body ?? &quot;&quot;;
    }
  }
  </code></pre>
  <p>this is my print of data in this get method, apparently he's not giving me the full json feedback from the api, but why?</p>
  <pre><code>status codeData {codigo_cupom: null, data_acao: 2021-07-26, deleted_at: null, descricao: Um Story, hashtags: null, hora_final_acao: 12:00:00, hora_inicial_acao: 08:00:00, job: {canal_entrada: E-Mail, cliente: {cidade: Portland, cliente_id: 1, cnpj: 12.345.678/0001-12, deleted_at: null, descricao: Nike, endereco: 1 Nike Drive, estado: SP, last_modified_by: null, last_time: 2021-07-11T19:13:54+00:00, login_instagram: nike, nome: Nike, nota_fiscal: null, numero_seguidores_instagram: null, observacoes: null, razao_social: Nike Inc, telefone_comercial: (11) 1111-1111, website: https://nike.com}, cliente_id: 1, data_inicio: 2021-07-24, deleted_at: null, descricao: Mais um teste, influenciador: {altura: null, avatar: pessoas/21/avatar.png, busto_cms: null, calcinha_sunga_tamanho: null, casting_mailing: null, cidade: null, cidade_nascimento: null, cintura_cms: null, cnpj: 27179660000138, cor_cabelo: null, cor_olhos: null, cpf: 048.677.923-81, dados_bancarios_agencia: 1322, dados_bancarios_banco: 12, dados_bancarios_
  </code></pre>
  <p>this is my model</p>
  <pre><code>class ActionPageModel {
    String influencerNome;
    String sobreNome;
    String descricaoJob;
    String nome;
    String dataDoJob;
    String horarioDoJob;
    String briefing;
    String site;
    String hashTag;
    String cupom;
    ActionPageModel({
      required this.influencerNome,
      required this.sobreNome,
      required this.descricaoJob,
      required this.nome,
      required this.dataDoJob,
      required this.horarioDoJob,
      required this.briefing,
      required this.site,
      required this.hashTag,
      required this.cupom,
    });
    
  
    Map&lt;String, dynamic&gt; toMap() {
      return {
        'influencerNome': influencerNome,
        'sobreNome': sobreNome,
        'descricaoJob': descricaoJob,
        'nome': nome,
        'dataDoJob': dataDoJob,
        'horarioDoJob': horarioDoJob,
        'briefing': briefing,
        'site': site,
        'hashTag': hashTag,
        'cupom': cupom,
      };
    }
  
    factory ActionPageModel.fromMap(Map&lt;String, dynamic&gt; map) {
      return ActionPageModel(
        influencerNome: map[&quot;influenciador&quot;][&quot;nome&quot;],
        sobreNome: map['influenciador'][&quot;sobrenome&quot;],
        descricaoJob: map['job'][&quot;cliente&quot;][&quot;descricao&quot;] ?? &quot;&quot;,
        nome: map['job'][&quot;cliente&quot;]['nome'] ?? &quot;&quot;,
        dataDoJob: map['data_acao'] ?? &quot;&quot;,
        horarioDoJob: map['hora_inicial_acao'] ?? &quot;&quot;,
        briefing: map['descricao'] ?? &quot;&quot;, //!FICAR DE OLHO NESSE CAMPO,
        site: map['job'][&quot;cliente&quot;][&quot;website&quot;] ?? &quot;&quot;,
        hashTag: map['hashtags'] ?? &quot;&quot;,
        cupom: map['codigo_cupom'] ?? &quot;&quot;,
      );
    }
  
    String toJson() =&gt; json.encode(toMap());
  
    factory ActionPageModel.fromJson(String source) =&gt; ActionPageModel.fromMap(json.decode(source));
  }
  </code></pre>
  <p>and this is json, it's quite long but I marked with this the areas I need to get the data</p>
  <pre><code>{
      &quot;codigo_cupom&quot;: null, //THIS
      &quot;data_acao&quot;: &quot;2021-07-26&quot;, //THIS
      &quot;deleted_at&quot;: null,
      &quot;descricao&quot;: &quot;Um Story&quot;,
      &quot;hashtags&quot;: null,
      &quot;hora_final_acao&quot;: &quot;12:00:00&quot;,
      &quot;hora_inicial_acao&quot;: &quot;08:00:00&quot;, //THIS
      &quot;job&quot;: {
          &quot;canal_entrada&quot;: &quot;E-Mail&quot;,
          &quot;cliente&quot;: {
              &quot;cidade&quot;: &quot;Portland&quot;,
              &quot;cliente_id&quot;: 1,
              &quot;cnpj&quot;: &quot;12.345.678/0001-12&quot;,
              &quot;deleted_at&quot;: null,
              &quot;descricao&quot;: &quot;Nike&quot;, //THIS
              &quot;endereco&quot;: &quot;1 Nike Drive&quot;,
              &quot;estado&quot;: &quot;SP&quot;,
              &quot;last_modified_by&quot;: null,
              &quot;last_time&quot;: &quot;2021-07-11T19:13:54+00:00&quot;,
              &quot;login_instagram&quot;: &quot;nike&quot;,
              &quot;nome&quot;: &quot;Nike&quot;, //THIS
              &quot;nota_fiscal&quot;: null,
              &quot;numero_seguidores_instagram&quot;: null,
              &quot;observacoes&quot;: null,
              &quot;razao_social&quot;: &quot;Nike Inc&quot;,
              &quot;telefone_comercial&quot;: &quot;(11) 1111-1111&quot;,
              &quot;website&quot;: &quot;https://nike.com&quot; //THIS
          },
          &quot;cliente_id&quot;: 1,
          &quot;data_inicio&quot;: &quot;2021-07-24&quot;,
          &quot;deleted_at&quot;: null,
          &quot;descricao&quot;: &quot;Mais um teste&quot;,
          &quot;influenciador&quot;: {
              &quot;altura&quot;: null,
              &quot;avatar&quot;: &quot;pessoas/21/avatar.png&quot;,
              &quot;busto_cms&quot;: null,
              &quot;calcinha_sunga_tamanho&quot;: null,
              &quot;casting_mailing&quot;: null,
              &quot;cidade&quot;: null,
              &quot;cidade_nascimento&quot;: null,
              &quot;cintura_cms&quot;: null,
              &quot;cnpj&quot;: &quot;27179660000138&quot;,
              &quot;cor_cabelo&quot;: null,
              &quot;cor_olhos&quot;: null,
              &quot;cpf&quot;: &quot;048.677.923-81&quot;,
              &quot;dados_bancarios_agencia&quot;: 1322,
              &quot;dados_bancarios_banco&quot;: 12,
              &quot;dados_bancarios_conta&quot;: &quot;0283614-9&quot;,
              &quot;dados_bancarios_pf_chave_pix&quot;: null,
              &quot;dados_bancarios_pf_cpf&quot;: null,
              &quot;dados_bancarios_pf_nome&quot;: null,
              &quot;dados_bancarios_pj_agencia&quot;: null,
              &quot;dados_bancarios_pj_banco&quot;: null,
              &quot;dados_bancarios_pj_chave_pix&quot;: null,
              &quot;dados_bancarios_pj_conta&quot;: null,
              &quot;data_nascimento&quot;: &quot;1987-11-25&quot;,
              &quot;deleted_at&quot;: null,
              &quot;email&quot;: &quot;influenciador@teste.com.br&quot;,
              &quot;email_responsavel_mailing&quot;: null,
              &quot;endereco&quot;: &quot;R SANTA JUSTINA 411, APTO 36           &quot;,
              &quot;estado&quot;: null,
              &quot;estado_civil&quot;: null,
              &quot;estado_nascimento&quot;: null,
              &quot;etnia&quot;: null,
              &quot;filhos&quot;: null,
              &quot;formacao&quot;: null,
              &quot;frase_destaque&quot;: &quot;Minha frase de destaque&quot;,
              &quot;influenciador_id&quot;: 21,
              &quot;last_modified_by&quot;: 21,
              &quot;last_time&quot;: &quot;2021-10-30T16:36:34+00:00&quot;,
              &quot;login_instagram&quot;: &quot;instagram&quot;,
              &quot;login_twitter&quot;: null,
              &quot;manequim_baixo&quot;: 40,
              &quot;manequim_cima&quot;: 38,
              &quot;marca_dedicada&quot;: null,
              &quot;nome&quot;: &quot;Isabela&quot;, //THIS
              &quot;nome_artistico&quot;: &quot;Influenciador Teste&quot;,
              &quot;nome_responsavel_mailing&quot;: null,
              &quot;numero_sapato&quot;: null,
              &quot;numero_seguidores_instagram&quot;: 404000000,
              &quot;numero_soutien&quot;: null,
              &quot;percentual_comissao&quot;: null,
              &quot;periodo_dedicado&quot;: null,
              &quot;peso&quot;: null,
              &quot;pessoa_id&quot;: 21,
              &quot;pets&quot;: null,
              &quot;quadril_cms&quot;: null,
              &quot;razao_social&quot;: null,
              &quot;responsavel&quot;: 3,
              &quot;responsavel_id&quot;: 3,
              &quot;rg&quot;: &quot;26.108.098-2&quot;,
              &quot;sexo&quot;: &quot;M&quot;,
              &quot;sobrenome&quot;: &quot;Soller&quot;, //THIS
              &quot;telefone&quot;: &quot;(11) 9999-9999&quot;,
              &quot;telefone_responsavel_mailing&quot;: null,
              &quot;texto&quot;: null,
              &quot;tipo_cabelo&quot;: null,
              &quot;token_senha&quot;: &quot;9738873473ADFD6464169415AA5CB4E1E39982E2E90F11D37E8B9383FE72040B6452C98774CB0E7B&quot;,
              &quot;url&quot;: null,
              &quot;url_facebook&quot;: null,
              &quot;url_media_kit&quot;: null,
              &quot;url_youtube&quot;: null,
              &quot;valor_pacote_fotos&quot;: 0.00,
              &quot;valor_post&quot;: 0.00,
              &quot;valor_post_facebook&quot;: 0.00,
              &quot;valor_post_stories&quot;: 0.00,
              &quot;valor_presenca&quot;: 0.00,
              &quot;valor_shooting&quot;: 0.00,
              &quot;valor_stories&quot;: 0.00,
              &quot;valor_take_over&quot;: 0.00,
              &quot;valor_video&quot;: 0.00,
              &quot;valor_youtube&quot;: 0.00
          },
          &quot;influenciador_id&quot;: 21,
          &quot;job_id&quot;: 3,
          &quot;last_modified_by&quot;: 1,
          &quot;last_time&quot;: &quot;2021-07-20T22:35:27+00:00&quot;,
          &quot;nota_fiscal&quot;: false,
          &quot;observacoes&quot;: null,
          &quot;participacao&quot;: 100,
          &quot;quantidade_posts&quot;: 1,
          &quot;quantidade_presencas&quot;: 1,
          &quot;quantidade_stories&quot;: 1,
          &quot;status&quot;: &quot;nao_iniciado&quot;,
          &quot;tipo_demanda&quot;: &quot;Espontâneo&quot;,
          &quot;valor&quot;: 9000.00
      },
      &quot;job_acao_comunicacoes&quot;: [],
      &quot;job_acao_id&quot;: 4,
      &quot;last_modified_by&quot;: 1,
      &quot;last_time&quot;: &quot;2021-07-20T22:35:27+00:00&quot;,
      &quot;link_produto&quot;: null,
      &quot;periodo&quot;: &quot;Manhã&quot;,
      &quot;status&quot;: &quot;nao_iniciada&quot;,
      &quot;tipo_acao&quot;: &quot;Story&quot;,
      &quot;titulo&quot;: &quot;Um Story&quot;,
      &quot;valor&quot;: 3000.00
  }
  </code></pre>
  <p>this is my error cath by printing stacktrace.</p>
  <pre><code>I/flutter ( 2931): NoSuchMethodError: The method '[]' was called on null.
  I/flutter ( 2931): Receiver: null
  I/flutter ( 2931): Tried calling: [](&quot;nome&quot;)
  I/flutter ( 2931): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
  I/flutter ( 2931): #1      new ActionPageModel.fromMap
  package:soller_acessoria_new_app_nullsafety/…/actionPageModel/action_page_model.dart:45
  I/flutter ( 2931): #2      ActionPageRepositoryImpl.getActionPageJobs.&lt;anonymous closure&gt;
  package:soller_acessoria_new_app_nullsafety/…/actionPage/action_page_repository_impl.dart:28
  I/flutter ( 2931): #3      bodyDecoded
  package:get/…/utils/body_decoder.dart:28
  I/flutter ( 2931): #4      HttpRequestImpl.send
  package:get/…/io/http_request_io.dart:60
  I/flutter ( 2931): &lt;asynchronous suspension&gt;
  I/flutter ( 2931): #5      GetHttpClient._performRequest
  package:get/…/src/http.dart:209
  I/flutter ( 2931): &lt;asynchronous suspension&gt;
  I/flutter ( 2931): #6      GetHttpClient.get
  package:get/…/src/http.dart:455
  I/flutter ( 2931): &lt;asynchronous suspension&gt;
  I/flutter ( 2931): #7      ActionPageRepositoryImpl.getActionPageJobs
  package:soller_acessoria_new_app_nullsafety/…/actionPage/action_page_repository_impl.dart:21
  I/flutter ( 2931): &lt;asynchronous suspension&gt;
  I/flutter ( 2931): #8      AcaoController.o
  </code></pre>