title: How do I fix "The method was called on null" error?
body: <p>I'm trying to create an object out of form and add it into the database.</p>
  
  <p>I printed all the values before calling the function and none of them are null.</p>
  
  <p>This is where i get the error</p>
  
  <pre class="lang-dart prettyprint-override"><code>Exercise ex=new Exercise(name: name,description: description,type:inputType,mainMuscle: inputMainMuscle,equipment:equip,userCreated: 1);
  
                   _databaseHelper.addExercise(ex).then((exerciseid){
                     if(exerciseid!=0){
                       Navigator.pop(context);
                     }
                   }
  </code></pre>
  
  <p>This is my function:</p>
  
  <pre class="lang-dart prettyprint-override"><code>Future&lt;int&gt; addExercise(Exercise exercise) async{
      var db = await _getDatabase();
      var sonuc = await db.insert("exercises", exercise.toMap());
      return sonuc;
   }
  </code></pre>
  
  <p>And this is my contructor:</p>
  
  <pre class="lang-dart prettyprint-override"><code>Exercise({this.name,this.description='Henüz bir açıklama eklenmemiş ☹️',this.type, this.equipment,this.mainMuscle='Undefined',this.userCreated});
  </code></pre>
  
  <pre class="lang-sh prettyprint-override"><code>
  flutter: ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
  flutter: The following NoSuchMethodError was thrown while handling a gesture:
  flutter: The method 'addExercise' was called on null.
  flutter: Receiver: null
  flutter: Tried calling: addExercise(Instance of 'Exercise')
  flutter:
  flutter: When the exception was thrown, this was the stack:
  flutter: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
  flutter: #1      _CreateExerciseState.build.&lt;anonymous closure&gt; (package:gymapp/view/viewmodels/createexercise.dart:99:34)
  flutter: #2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
  flutter: #3      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:710:32)
  flutter: #4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
  flutter: #5      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
  flutter: #6      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
  flutter: #7      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
  flutter: #8      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
  flutter: #9      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
  flutter: #10     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
  flutter: #11     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
  flutter: #12     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
  flutter: #13     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
  flutter: #14     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
  flutter: #18     _invoke1 (dart:ui/hooks.dart:263:10)
  flutter: #19     _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
  flutter: (elided 3 frames from package dart:async)
  flutter:
  flutter: Handler: "onTap"
  flutter: Recognizer:
  flutter:   TapGestureRecognizer#225e0
  flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
  </code></pre>