title: Unhandled Exception: NoSuchMethodError while setting values in setter in Model class
body: <p>I'm learning flutter programming. I'm making a simple registration form with just 2 fields for now, name and dob. I have successfully create a simple note making application with db so followed the same instructions here. But running into an error "Unhandled Exception: NoSuchMethodError: The setter 'regday=' was called on null."</p>
  
  <p><strong>Registration model class</strong></p>
  
  <pre><code>class RegistrationModel
  {
    int _id;
    String _name;
    String _dob;
    String _regDay;
  
    RegistrationModel(this._name, this._dob, [this._regDay]);
  
    RegistrationModel.withId(this._id, this._name, this._dob, [this._regDay]);
  
    //GETTERS
    int get id =&gt; _id;
  
    String get name =&gt; _name;
  
    String get dob =&gt; _dob;
  
    String get regday =&gt; _regDay;
  
    //SETTER
    set name(String newName)
    {
      if(newName.length &lt;= 30)
        {
          this._name = newName.trim();
        }
    }
  
    set dob(String newDob)
    {
      this._dob = newDob;
    }
  
    set regday(String newRegDay)
    {
      print("New Reg Day : $newRegDay");
      this._regDay = newRegDay;
    }
  
    //CONVERT REG OBJ TO MAP
    Map&lt;String, dynamic&gt; toMap()
    {
      var map = Map&lt;String, dynamic&gt;();
  
      if(id != null)
        {
          map['id'] = _id;
        }
      map['name'] = _name;
      map['dob'] = _dob;
      map['regday'] = _regDay;
  
      return map;
    }
  
    //CONVERT MAP TO REG
    RegistrationModel.fromMapObject(Map&lt;String, dynamic&gt; map){
      this._id = map['id'];
      this._name = map['name'];
      this._dob = map['dob'];
      this._regDay = map['regday'];
    }
  }
  </code></pre>
  
  <p><strong>Code which sets the value</strong></p>
  
  <pre><code>class Registration extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() {
      return RegistrationState();
    }
  }
  
  class RegistrationState extends State {
    RegistrationModel reg;
  
    DatabaseHelper databaseHelper = DatabaseHelper();
  
    var _minimumPadding = 5.0;
    var _formKey;
  
    TextEditingController _nameController = new TextEditingController();
    TextEditingController _dobController = new TextEditingController();
  
    @override
    Widget build(BuildContext context) {
      TextStyle textStyle = Theme.of(context).textTheme.title;
  
  //    _nameController.text = reg.name;
  //    _dobController.text = reg.dob;
  
      //DATEPICKER
      DateTime _selectedDate = DateTime.now();
  
      Future&lt;Null&gt; _selectDate(BuildContext context) async {
        final DateTime picked = await showDatePicker(
            context: context,
            initialDate: _selectedDate,
            firstDate: DateTime(1990),
            lastDate: DateTime(2101));
        if (picked != null &amp;&amp; picked != _selectedDate) {
          print("Selected Date in the func : $picked");
          setState(() {
            _selectedDate = picked;
            _dobController.text = (picked.day).toString() +
                "/" +
                (picked.month).toString() +
                "/" +
                (picked.year).toString();
          });
  //        Focus.clear(context);
  
        }
      }
  
      return Scaffold(
        appBar: AppBar(
          title: Text("Register"),
        ),
        body: Form(
          key: _formKey,
          child: Padding(
            padding: EdgeInsets.only(
              top: _minimumPadding * 2,
              left: _minimumPadding * 2,
              right: _minimumPadding * 2,
            ),
            child: ListView(
              children: &lt;Widget&gt;[
                //NAME
                TextField(
                  controller: _nameController,
                  style: textStyle,
                  onChanged: (value) {
                    updateName();
                  },
                  decoration: InputDecoration(
                    labelStyle: textStyle,
                    labelText: "Name",
                    icon: Icon(Icons.person),
                  ),
                ),
  
                //DATE OF BIRTH
                TextField(
                  controller: _dobController,
                  keyboardType: TextInputType.datetime,
                  onChanged: (value) {
                    updateDob();
                  },
                  decoration: InputDecoration(
                    labelStyle: textStyle,
                    labelText: "Date Of Birth",
                    icon: Icon(Icons.calendar_today),
                  ),
                  onTap: () {
                    _selectDate(context);
                  },
                ),
  
                RaisedButton(
                  child: Text(
                    "Register",
                    textScaleFactor: 1.5,
                  ),
                  color: Theme.of(context).primaryColor,
                  textColor: Theme.of(context).primaryColorLight,
                  onPressed: () {
                    _save();
                    print("Save button pressed");
                  },
                ),
              ],
            ),
          ),
        ),
      );
    }
  
  void _save() async {
  
      String today = DateFormat.yMMMd().format(DateTime.now());
      print("Today : $today");
      reg.regday = today;
      reg.name = _nameController.text;
      reg.dob = _dobController.text;
  
      int result;
      if (reg.id != null) //UPDATE
      {
        result = await databaseHelper.updateRegister(reg);
      } else {
        result = await databaseHelper.inserRegister(reg);
      }
  
      if (result != 0) //SUCCESS
      {
        _showAlertDialog("Success", "Registered successfully");
      } else //FAILED
      {
        _showAlertDialog("Failed", "Problem in registering");
      }
    }
  </code></pre>
  
  <p><strong>The trace</strong></p>
  
  <pre><code>[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The setter 'regday=' was called on null.
  E/flutter (21661): Receiver: null
  E/flutter (21661): Tried calling: regday="Apr 1, 2019"
  E/flutter (21661): #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
  E/flutter (21661): #1      RegistrationState._save (package:registration_test/screens/registration_screen.dart:136:9)
  E/flutter (21661): &lt;asynchronous suspension&gt;
  E/flutter (21661): #2      RegistrationState.build.&lt;anonymous closure&gt; (package:registration_test/screens/registration_screen.dart:111:19)
  E/flutter (21661): #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14)
  E/flutter (21661): #4      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:568:30)
  E/flutter (21661): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:120:24)
  E/flutter (21661): #6      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
  E/flutter (21661): #7      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
  E/flutter (21661): #8      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
  E/flutter (21661): #9      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:20)
  E/flutter (21661): #10     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22)
  E/flutter (21661): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7)
  E/flutter (21661): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
  E/flutter (21661): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
  E/flutter (21661): #14     _rootRunUnary (dart:async/zone.dart:1136:13)
  E/flutter (21661): #15     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
  E/flutter (21661): #16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
  E/flutter (21661): #17     _invoke1 (dart:ui/hooks.dart:223:10)
  E/flutter (21661): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5)
  
  </code></pre>
  
  <p>The expected output will be an alert box displaying the success message, but instead throws this error. Any help will be greatly appreciated.</p>