Apress / practical-flutter

Source Code for 'Practical Flutter' by Frank Zammetti
https://www.apress.com/9781484249710
Other
125 stars 89 forks source link

AppointmentsEntry error during build #6

Closed rogersnowden closed 4 years ago

rogersnowden commented 5 years ago

New to dart/flutter, so learning to debug with Android Studio. Interesting, but a bit confusing. Using the git code, I have this error: I/flutter (21442): ## AppointmentsEntry.build() I/flutter (21442): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (21442): The following NoSuchMethodError was thrown building AppointmentsEntry(dirty): I/flutter (21442): The getter 'title' was called on null. I/flutter (21442): Receiver: null I/flutter (21442): Tried calling: title I/flutter (21442): I/flutter (21442): User-created ancestor of the error-causing widget was: I/flutter (21442): IndexedStack file:///D:/FlutterProjects/flutter_book/lib/ap pointments/Appointments.dart:38:18 I/flutter (21442): I/flutter (21442): When the exception was thrown, this was the stack: I/flutter (21442): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5) I/flutter (21442): #1 AppointmentsEntry.build (package:flutter_book/appointments/AppointmentsEntry.dart:49:72) I/flutter (21442): #2 StatelessElement.build (package:flutter/src/widgets/framework.dart:4026:28) ... etc...

I tried just plugging a hard coded value to the text element, but to no avail. This section of AppointmentsEntry... print("## AppointmentsEntry.build()");

// Set value of controllers.
_titleEditingController.text = appointmentsModel.entityBeingEdited.title;
_descriptionEditingController.text = appointmentsModel.entityBeingEdited.description;

... seems to be where the title element of appointmentsModel.entityBeingEdited is assigned. According to the next "up" stack entry, Object.noSuchMethod implies this data element is a method, or the idea of an "=" assignment is in valid. Counterintuitive, at best.

What am I missing here? I keep looking at the class definitions, but nothing bad jumps out at me.

Does this code for for others?

fzammetti commented 4 years ago

I just checked in an update that brings the project into compliance for the latest version of Flutter (as of 2/15/2020) including updates to most dependencies to their latest and Android SDK 28. It includes a fix for this specific error as well (simple answer is just to do a null check before trying to set the values in the lines you referenced). Everything is working for me, hopefully everyone else as well.