The getter " type" was called on null. error in flutter

1143 views flutter dropdown

I have a function like this,

  changingTheSubjectOptions() {
    if (registerType.type == "Teacher") {
      subjectsOptionShow = true;
    } else {
      subjectsOptionShow = false;
    return subjectsOptionShow;

Here the value of registerType.type is changing when the user selects the dropdown option here,

  RegisterType registerType;
  List<RegisterType> registrationList = <RegisterType>[
    RegisterType(type: "Student"),
    RegisterType(type: "Teacher"),

                    value: registerType,
                    icon: Icon(Icons.arrow_downward),
                    iconSize: 24,
                    elevation: 16,
                    hint: Container(
                      // width: 200,
                      child: Text("You are ",
                          style: TextStyle(
                              color: Colors.grey,
                              fontWeight: FontWeight.w600,
                              fontSize: 15)),
                    underline: Container(
                      color: Colors.white,
                    style: TextStyle(color:,
                    onChanged: (RegisterType newValue) {
                      setState(() {
                        registerType = newValue;
                    items: registrationList
                            (RegisterType value) {
                      return DropdownMenuItem<RegisterType>(
                        value: value,
                        child: Text(value.type),

Now when I call the function like this,

                visible: changingTheSubjectOptions(),

it gives an error,
The getter 'type' was called on null.
Upto here I understand that registerType.type is null.
But also after I initialize the registerType.type in initState, it gives the same error.

  void initState() {
    registerType.type = "Student";

How can I initialize it?

answered question

1 Answer


registerType is null, not registerType.type. Maybe initialize it to something or use it with null checks.

posted this

Have an answer?


Please login first before posting an answer.