The following NoSuchMethodError was thrown building Builder: The getter 'alOne' was called on null. Receiver: null Tried calling: alOne

1,565 views
Skip to first unread message

Error Place

unread,
Apr 13, 2020, 11:03:16 AM4/13/20
to Flutter Development (flutter-dev)
anyone knows what has gone wrong here?
i am not getting any warnings in the dart analysis but this error is thrown and the page crashes!
thank you all.

class MondayScreen extends StatefulWidget {
static final String id = 'monday_screen';
final User user;

MondayScreen({this.user});

@override
_MondayScreenState createState() => _MondayScreenState();
}

class _MondayScreenState extends State<MondayScreen> {
final _formKey = GlobalKey<FormState>();

String _alOne = '';


@override
void initState() {
super.initState();
_alOne = widget.user.alOne;
}

_submit() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
User user = User(
id: widget.user.id,
alOne: _alOne,
);

DatabaseService.updateUser(user);
Navigator.pop(context);
}
}



//user_models

class User(
final String id;
final String name;

final String profileImageUrl;

final String email;

final String alOne;

)


User({
this.id;
this.name;

this.profileImageUrl;

this.email;

this.bio;

this.alOne;
)}


Souvik Dutta

unread,
Apr 13, 2020, 11:06:54 AM4/13/20
to Error Place, Flutter Development (flutter-dev)
You forgot await inside your async function. That is needed because it takes some time to complete the query. So the initial value is set to null.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f83d41e9-a73b-4bdf-9175-d77c6ec1ba04%40googlegroups.com.

Error Place

unread,
Apr 13, 2020, 11:40:41 AM4/13/20
to Flutter Development (flutter-dev)
 TextFormField(
initialValue: _alOne,
style: TextStyle(fontSize: 18.0),
decoration: InputDecoration(
labelText: 'Alternativ',
),
validator: (input) => input.trim().length > 100
? 'Please enter a valid name'
: null,
onSaved: (input) => _alOne = input),
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Suzuki Tomohiro

unread,
Apr 13, 2020, 11:58:45 AM4/13/20
to Flutter Development (flutter-dev)
Would you share stack trace and your code with line number?

Then I will point out that the variable left to “.alOne” was null.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Error Place

unread,
Apr 13, 2020, 12:02:26 PM4/13/20
to Flutter Development (flutter-dev)
hi suziki.
this is the stack trace
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building Builder:
The getter 'alOne' was called on null.
Receiver: null
Tried calling: alOne

The relevant error-causing widget was: 
  MaterialApp file:///Users/alirezamohebbi/AndroidStudioProjects/lunch_nu/lib/main.dart:38:14
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      _MondayScreenState.initState (package:lun/screen/monday_screen.dart:28:26)
#2      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
#3      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#4      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
...


and this is the line

_alOne = widget.user.alOne;
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Andy Greenshaw

unread,
Apr 13, 2020, 12:06:46 PM4/13/20
to Error Place, Flutter Development (flutter-dev)
So widget.user is null


From: flutt...@googlegroups.com <flutt...@googlegroups.com> on behalf of Error Place <reza7....@gmail.com>
Sent: Monday, April 13, 2020 5:02:26 PM
To: Flutter Development (flutter-dev) <flutt...@googlegroups.com>
Subject: Re: The following NoSuchMethodError was thrown building Builder: The getter 'alOne' was called on null. Receiver: null Tried calling: alOne
 
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/65da6678-941d-4df2-a4db-7500b909f6dd%40googlegroups.com.

Souvik Dutta

unread,
Apr 13, 2020, 12:22:35 PM4/13/20
to Error Place, Flutter Development (flutter-dev)
What is the 38th line of your project?

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/65da6678-941d-4df2-a4db-7500b909f6dd%40googlegroups.com.

Suzuki Tomohiro

unread,
Apr 13, 2020, 12:27:18 PM4/13/20
to Flutter Development (flutter-dev)
widget.user was null.

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/65da6678-941d-4df2-a4db-7500b909f6dd%40googlegroups.com.

Suzuki Tomohiro

unread,
Apr 13, 2020, 12:43:06 PM4/13/20
to Flutter Development (flutter-dev)
Great to heat it’s solved.

On Mon, Apr 13, 2020 at 12:28 PM Error Place <reza7....@gmail.com> wrote:
Thank you guys, Suzuki 🙌🏼 Solved 

Souvik Dutta

unread,
Apr 13, 2020, 9:12:23 PM4/13/20
to Error Place, Flutter Development (flutter-dev)
Who solved the problem? And how was it solved?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages