1
resposta

Tela vermelha ao tentar listar "Contatos"

Ao tentar listar contatos clicando no botão "Contacts" o app apresenta seguinte mensagem em tela vermelha:

"NoSuchMethodError: The getter 'length' was called on null. Receiver: null Tried calling: lentgh See also: https://flutter.dev/docs/testing/errors"

No console:

Performing hot restart... Syncing files to device AOSP on IA Emulator... Restarted application in 2,283ms. E/SQLiteLog( 8630): (1) no such table: contacts

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building FutureBuilder<List>(dirty, state: _FutureBuilderState<List>#45e5c): The getter 'length' was called on null. Receiver: null Tried calling: length

The relevant error-causing widget was: FutureBuilder<List> file:///home/meunome/Documents/01_Courses/App%20Mobile/Flutter/bytebanktwo/lib/screens/contacts_list.dart:16:13 When the exception was thrown, this was the stack:

#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

#1 ContactsList.build. (package:bytebanktwo/screens/contacts_list.dart:44:37)

#2 _FutureBuilderState.build (package:flutter/src/widgets/async.dart)

#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)

#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15) ... ════════════════════════════════════════════════════════════════════════════════════════════════════

1 resposta

Olá Anderson, tudo bem com você?

Acredito que já deve ter encontrado seu erro, caso não, pela mensagem você postou:

 null Tried calling: lentgh 

Na hora de fazer o ListView.builder() provavelmente você escreveu lentgh ao invés de length no itemCount, dessa forma tivemos o lançamento de erro!

Modificando para:

itemCount: contacts.length

Já deve voltar tudo ao normal

Abraços e Bons Estudos :)