title: _Cast Error : Null check operator used on a null value
body: <p>I am new to programming and don't know how to solve this issue.
  I am using the java version of 8 and using Android Studio to make apps with Flutter.
  I have been making a to-do list app, and a cast error happens when</p>
  <ul>
  <li>I make a new list</li>
  <li>I update a list</li>
  <li>I delete a list</li>
  </ul>
  <pre><code>    class MyApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return MaterialApp(
            title: 'Flutter ToDo List',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              fontFamily: &quot;NanumSquare&quot;,
              primaryColor: Color(0xFF424874), //primary color
            ),
              home: HomeScreen()
          );
        }
      }
  </code></pre>
  <p>this is the main.dart</p>
  <p>the error appears on the Home Screen.</p>
  <pre><code> class HomeScreen extends StatefulWidget {
  
    @override
    _HomeScreenState createState() =&gt; _HomeScreenState();
  }
  
  class _HomeScreenState extends State&lt;HomeScreen&gt; {
    late Future&lt;List&lt;Note&gt;&gt; _noteList;
    final DateFormat _dateFormatter = DateFormat(&quot;MMM dd, yyyy&quot;);
  
    DatabaseHelper _databaseHelper = DatabaseHelper.instance;
  
    void initState() {
      super.initState();
      _updateNoteList();
    }
  
    _updateNoteList() {
      _noteList = DatabaseHelper.instance.getNoteList();
    }
  
    Widget _buildNote(Note note) {
      return Padding(
        padding: EdgeInsets.symmetric(horizontal: 25),
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.all(5),
              color: Color(0xFFDCD6F7),
              child: ListTile(
                title: Text(
                  note.title!,
                  style: TextStyle(
                      fontSize: 20,
                      color: Color(0xFF424874),
                      decoration: note.status == 0
                          ? TextDecoration.none
                          : TextDecoration.lineThrough),
                ),
                subtitle: Text(
                  &quot;${_dateFormatter.format(note.date!)}-${note.priority}&quot;,
                  style: TextStyle(
                      fontSize: 15,
                      color: Color(0xFF424874),
                      decoration: note.status == 0
                          ? TextDecoration.none
                          : TextDecoration.lineThrough),
                ),
                trailing: Checkbox(
                  onChanged: (value) {
                    note.status = value! ? 1 : 0;
                    DatabaseHelper.instance.updateNote(note);
                    _updateNoteList();
                    Navigator.pushReplacement(
                        context, MaterialPageRoute(builder: (_) =&gt; HomeScreen())
                    );
                  },
                  activeColor: Color(0xFFA6B1E1),
                  value: note.status == 1 ? true : false,
                ),
                onTap: () =&gt; Navigator.push(
                    context,
                    CupertinoPageRoute(
                        builder: (_) =&gt; AddNoteScreen(
                            updateNoteList: _updateNoteList(),
                            note: note
                        )
                    ),
                ),
              ),
            ),
            Divider(
              height: 5,
              color: Color(0xFFA6B1E1),
              thickness: 2,
            )
          ],
        ),
      );
    }
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          backgroundColor: Color(0xFFF4EEFF),
          floatingActionButton: FloatingActionButton(
            backgroundColor: Color(0xFF424874),
            onPressed: () {
              Navigator.push(
                  context,
                  CupertinoPageRoute(
                    builder: (_) =&gt; AddNoteScreen(
                      updateNoteList: _updateNoteList(),
                    ),
                  ));
            },
            child: Icon(Icons.add),
          ),
          body: FutureBuilder(
              future: _noteList,
              builder: (context, AsyncSnapshot snapshot) {
                if (!snapshot.hasData) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                }
                final int completedNoteCount = snapshot.data!.where((Note note) =&gt; note.status == 1).toList().length;
                
                return ListView.builder(
                    padding: EdgeInsets.symmetric(vertical: 80),
                    itemCount: int.parse(snapshot.data!.length.toString()) + 1,
                    itemBuilder: (BuildContext context, int index) {
                      if (index == 0) {
                        return Padding(
                          padding:
                              EdgeInsets.symmetric(horizontal: 40, vertical: 20),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                &quot;My Notes&quot;,
                                style: TextStyle(
                                    color: Color(0xFF424874),
                                    fontSize: 40,
                                    fontWeight: FontWeight.bold),
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Text(
                                &quot;$completedNoteCount of ${snapshot.data.length}&quot;,
                                style: TextStyle(
                                    color: Color(0xFFA6B1E1),
                                    fontSize: 20,
                                    fontWeight: FontWeight.w600),
                              ),
                            ],
                          ),
                        );
                      }
                      return _buildNote(snapshot.data![index-1]);
                    });
              }));
    }
  }
  </code></pre>
  <p>The error message is as below.</p>
  <pre><code>======== Exception caught by gesture ===============================================================
  The following _CastError was thrown while handling a gesture:
  Null check operator used on a null value
  
  When the exception was thrown, this was the stack: 
  #0      _AddNoteScreenState._delete (package:crud_sqlite_app/screens/add_note_screen.dart:80:26)
  #1      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
  #2      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
  #3      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
  #4      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
  ...
  Handler: &quot;onTap&quot;
  Recognizer: TapGestureRecognizer#e7613
    debugOwner: GestureDetector
    state: ready
    won arena
    finalPosition: Offset(150.8, 655.2)
    finalLocalPosition: Offset(110.8, 46.2)
    button: 1
    sent tap down
  
  ====================================================================================================
  </code></pre>
  <p>and this is the add_note_screen.dart</p>
  <pre><code>class AddNoteScreen extends StatefulWidget {
    final Note? note;
    final Function? updateNoteList;
    AddNoteScreen({this.note, this.updateNoteList});
  
    @override
    _AddNoteScreenState createState() =&gt; _AddNoteScreenState();
  }
  
  class _AddNoteScreenState extends State&lt;AddNoteScreen&gt; {
    final _formKey = GlobalKey&lt;FormState&gt;();
    String _title = &quot;&quot;;
    String _priority = &quot;Low&quot;;
    String btnText = &quot;Add Note&quot;;
    String titleText = &quot;Add Note&quot;;
  
    DateTime _date = DateTime.now();
    TextEditingController _dateController = TextEditingController();
    final DateFormat _dateFormatter = DateFormat(&quot;MMM dd, yyyy&quot;);
    final List&lt;String&gt; _priorities = [&quot;Low&quot;, &quot;Medium&quot;, &quot;High&quot;];
  
    @override
    void initState(){
      super.initState();
  
      if(widget.note != null) {
        _title = widget.note!.title!;
        _date = widget.note!.date!;
        _priority = widget.note!.priority!;
  
        setState(() {
          btnText = &quot;Update Note&quot;;
          titleText = &quot;Update Note&quot;;
        });
      }
      else {
        setState(() {
          btnText = &quot;Add Note&quot;;
          titleText = &quot;Add Note&quot;;
        });
      }
      _dateController.text = _dateFormatter.format(_date);
    }
  
    @override
    void dispose() {
      _dateController.dispose();
      super.dispose();
    }
  
    _handleDatePicker() async {
      final DateTime? date = await showDatePicker(
          context: context,
          initialDate: _date,
          firstDate: DateTime(2000),
          lastDate: DateTime(2100));
      if (date != null &amp;&amp; date != _date) {
        setState(() {
          _date = date;
        });
        _dateController.text = _dateFormatter.format(date);
      }
    }
  
    _delete() {
      DatabaseHelper.instance.deleteNote(widget.note!.id!);
      Navigator.pushReplacement(
          context,
          MaterialPageRoute(
              builder: (_)=&gt; HomeScreen()
          )
      );
      widget.updateNoteList!();
    }
  
    _submit() {
      if (_formKey.currentState!.validate()) {
        _formKey.currentState!.save();
        print(&quot;$_title, $_date, $_priority&quot;);
        
        Note note = Note(
          title: _title,
          date: _date,
          priority: _priority
        );
        if (widget.note == null){
          note.status = 0;
          DatabaseHelper.instance.insertNote(note);
          
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (_)=&gt; HomeScreen())
          );
        }
        else{
          note.id = widget.note!.id;
          note.status = widget.note!.status;
          DatabaseHelper.instance.updateNote(note);
  
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (_)=&gt; HomeScreen())
          );
        }
        widget.updateNoteList!();
      }
    }
  
  
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Color(0xFFF4EEFF),
        body: GestureDetector(
          onTap: () =&gt; FocusScope.of(context).unfocus(),
          child: SingleChildScrollView(
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 40, vertical: 80),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: &lt;Widget&gt;[
                  GestureDetector(
                    onTap: () =&gt; Navigator.pushReplacement(
                        context,
                        MaterialPageRoute(
                          builder: (_) =&gt; HomeScreen(),
                        )
                    ),
                    child: Icon(
                      Icons.arrow_back,
                      size: 30,
                      color: Color(0xFFA6B1E1),
                    ),
                  ),
                  SizedBox(
                    height: 20.0,
                  ),
                  Text(
                    titleText,
                    style: TextStyle(
                        color: Color(0xFF424874),
                        fontSize: 40,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Form(
                    key: _formKey,
                    child: Column(
                      children: &lt;Widget&gt;[
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 20),
                          child: TextFormField(
                            style: TextStyle(fontSize: 18),
                            decoration: InputDecoration(
                                labelText: &quot;Title&quot;,
                                labelStyle: TextStyle(fontSize: 18),
                                border: OutlineInputBorder(
                                    borderRadius: BorderRadius.circular(10))),
                            validator: (input) =&gt; input!.trim().isEmpty
                                ? &quot;Please enter a note title&quot;
                                : null,
                            onSaved: (input) =&gt; _title = input!,
                            initialValue: _title,
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 20),
                          child: TextFormField(
                            readOnly: true, //hide keyboard
                            controller: _dateController,
                            style: TextStyle(fontSize: 18),
                            onTap: _handleDatePicker,
                            decoration: InputDecoration(
                                labelText: &quot;Date&quot;,
                                labelStyle: TextStyle(fontSize: 18),
                                border: OutlineInputBorder(
                                    borderRadius: BorderRadius.circular(10))),
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 20),
                          child: DropdownButtonFormField(
                            isDense: true,
                            icon: Icon(Icons.arrow_drop_down_circle),
                            iconSize: 22,
                            iconEnabledColor: Color(0xFF424874),
                            items: _priorities.map((String priority) {
                              return DropdownMenuItem(
                                  value: priority,
                                  child: Text(
                                    priority,
                                    style: TextStyle(
                                      color: Colors.black,
                                      fontSize: 18,
                                    ),
                                  ));
                            }).toList(),
                            style: TextStyle(fontSize: 18),
                            decoration: InputDecoration(
                                labelText: &quot;Priority&quot;,
                                labelStyle: TextStyle(fontSize: 18),
                                border: OutlineInputBorder(
                                    borderRadius: BorderRadius.circular(10)
                                )
                            ),
                            // validator: (input) =&gt; _priority == null ? &quot;Please&quot;,
                            onChanged: (value) {
                              setState(() {
                                _priority = value.toString();
                              });
                            },
                            value: _priority,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.symmetric(vertical: 20),
                          height: 60.0,
                          width: double.infinity,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(30)),
                          child: ElevatedButton(
                            style: ButtonStyle(
                              backgroundColor: MaterialStateProperty.all(Theme.of(context).primaryColor)
                            ),
                            child: Text(
                              btnText,
                              style: TextStyle(color: Colors.white, fontSize: 20),
                            ),
                            onPressed: _submit,
                          ),
                        ),
                        widget.note != null ? Container(
                          margin: EdgeInsets.symmetric(vertical: 20),
                          height: 60,
                          width: double.infinity,
                          decoration: BoxDecoration(
                            color: Color(0xFF424874),
                            borderRadius: BorderRadius.circular(30)
                          ),
                          child: ElevatedButton(
                            style: ButtonStyle(
                                backgroundColor: MaterialStateProperty.all(Theme.of(context).primaryColor)
                            ),
                            child: Text(&quot;Delete Note&quot;,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 20
                            ),
                            ),
                            onPressed: _delete,
                          ),
                        ): SizedBox.shrink()
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>I am sorry the code is too long.
  If you can help me, I will really appreciate it.
  Thank you!</p>