1
resposta

Erro na execução do Future (The following NoSuchMethodError was thrown building FutureBuilder<List<Contact>>)

Quando eu executo o hotstart parece que ele executa corretamente o código. O emulador responde corretamente igual a aula. Mas, aparece este erro aqui no meu terminal:

Performing hot restart...                                               
Restarted application in 761ms.
I/flutter ( 7167): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 7167): The following NoSuchMethodError was thrown building FutureBuilder<List<Contact>>(dirty, state:
I/flutter ( 7167): _FutureBuilderState<List<Contact>>#8099c):
I/flutter ( 7167): The getter 'length' was called on null.
I/flutter ( 7167): Receiver: null
I/flutter ( 7167): Tried calling: length
I/flutter ( 7167): 
I/flutter ( 7167): The relevant error-causing widget was:
I/flutter ( 7167):   FutureBuilder<List<Contact>>
I/flutter ( 7167):   file:///home/l/IntelliJIDEAProjects/bytebank_2/lib/screens/contacts_list.dart:13:15
I/flutter ( 7167): 
I/flutter ( 7167): When the exception was thrown, this was the stack:
I/flutter ( 7167): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 7167): #1      ContactsList.build.<anonymous closure> (package:bytebank_2/screens/contacts_list.dart:23:35)
I/flutter ( 7167): #2      _FutureBuilderState.build (package:flutter/src/widgets/async.dart:751:55)
I/flutter ( 7167): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4744:28)
I/flutter ( 7167): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4627:15)
I/flutter ( 7167): #5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter ( 7167): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter ( 7167): #7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
I/flutter ( 7167): #8      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11)
I/flutter ( 7167): #9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
I/flutter ( 7167): ...     Normal element mounting (19 frames)
I/flutter ( 7167): #28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
I/flutter ( 7167): #29     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32)
I/flutter ( 7167): ...     Normal element mounting (208 frames)
I/flutter ( 7167): #237    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
I/flutter ( 7167): #238    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32)
I/flutter ( 7167): ...     Normal element mounting (273 frames)
I/flutter ( 7167): #511    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
I/flutter ( 7167): #512    Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
I/flutter ( 7167): #513    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1252:16)
I/flutter ( 7167): #514    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1223:5)
I/flutter ( 7167): #515    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1165:17)
I/flutter ( 7167): #516    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2683:19)
I/flutter ( 7167): #517    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1164:13)
I/flutter ( 7167): #518    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:974:7)
I/flutter ( 7167): #519    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:955:7)
I/flutter ( 7167): (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
I/flutter ( 7167): 
I/flutter ( 7167): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 7167): tamanho da lista: 2
I/flutter ( 7167): tamanho da lista: 2

Isso é um problema? Existe algo para ser corrigido?

1 resposta

Bom dia Lucas, você poderia, por gentileza me mostrar seu código do arquivo contacts_list.dart?

No caso desse Erro ele está dizendo que o tamanho da lista é 0 quando é construída, mas depois ele diz que o tamanho da lista é dois pelo seu código, gostaria de dar uma revisada para poder te ajudar :)