title: Flutter issue : type 'Null' is not a subtype of 'DateTime'
body: <p>I am looking for help on a personal project. Basically, I have calendar as an app drawer option, and it was working while I was still on the calendar page and hot reloading but now after a hot restart it keeps showing me this error</p>
  <pre><code>type 'Null' is not a subtype of type 'DateTime'
  </code></pre>
  <p>Here is my code for Calendar screen:</p>
  <pre><code>import 'package:attendance_checker/screens/home.dart';
  
  import 'package:flutter/material.dart';
  import 'package:table_calendar/table_calendar.dart';
  import 'package:attendance_checker/models/calendar_events.dart';
  
  class Calender extends StatefulWidget {
    const Calender({Key? key}) : super(key: key);
  
    @override
    _CalenderState createState() =&gt; _CalenderState();
  }
  
  class _CalenderState extends State&lt;Calender&gt; {
    late Map&lt;DateTime, List&lt;Event&gt;&gt; selectedEvents;
    CalendarFormat format = CalendarFormat.month;
    var focusedDay;
    var selectedDay;
  
    TextEditingController _eventController = TextEditingController();
  
    @override
    void initState() {
      selectedEvents = {};
      super.initState();
    }
  
    @override
    void dispose() {
      _eventController.dispose();
      super.dispose();
    }
  
    List&lt;Event&gt; _getEventsfromDay(DateTime date) {
      return selectedEvents[date] ?? [];
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          leading: BackButton(
              color: Colors.white,
              onPressed: () =&gt; Navigator.pushReplacement(
                  context, MaterialPageRoute(builder: (context) =&gt; Home()))),
          title: Text(&quot;Calendar&quot;),
          backgroundColor: Colors.green[700],
        ),
        body: SingleChildScrollView(
          child: Column(
            children: &lt;Widget&gt;[
              Column(
                children: [
                  TableCalendar(
                    focusedDay: DateTime.now(),
                    firstDay: DateTime.utc(2010, 10, 16),
                    lastDay: DateTime.utc(2030, 3, 14),
                    calendarFormat: format,
                    onFormatChanged: (CalendarFormat _format) {
                      setState(() {
                        format = _format;
                      });
                    },
                    eventLoader: _getEventsfromDay,
                    calendarStyle: CalendarStyle(
                        isTodayHighlighted: true,
                        selectedDecoration: BoxDecoration(
                          color: Colors.green[300],
                          shape: BoxShape.circle,
                        ),
                        selectedTextStyle: TextStyle(color: Colors.white),
                        todayDecoration: BoxDecoration(
                          color: Colors.green[700],
                          shape: BoxShape.circle,
                        )),
                    startingDayOfWeek: StartingDayOfWeek.sunday,
                    daysOfWeekVisible: true,
                    onDaySelected: (DateTime selectDay, DateTime focusDay) {
                      setState(() {
                        selectedDay = selectDay;
                        focusedDay = focusDay;
                      });
                      print(focusedDay);
                    },
                    selectedDayPredicate: (DateTime date) {
                      return isSameDay(selectedDay, date);
                    },
                    headerStyle: HeaderStyle(
                        formatButtonVisible: false, titleCentered: true),
                  ),
                  ..._getEventsfromDay(selectedDay).map((Event event) =&gt; ListTile(
                        title: Text(event.title),
                      )),
                ],
              )
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton.extended(
          onPressed: () =&gt; showDialog(
            context: context,
            builder: (context) =&gt; AlertDialog(
              title: Text(&quot;Add Event&quot;),
              content: TextFormField(
                controller: _eventController,
              ),
              actions: [
                TextButton(
                    onPressed: () =&gt; Navigator.pop(context),
                    child: Text(&quot;Cancel&quot;)),
                TextButton(
                    onPressed: () {
                      if (_eventController.text.isEmpty) {
                      } else {
                        if (selectedEvents[selectedDay] != null) {
                          selectedEvents[selectedDay]!
                              .add(Event(title: _eventController.text));
                        } else {
                          selectedEvents[selectedDay] = [
                            Event(title: _eventController.text)
                          ];
                        }
                      }
                      Navigator.pop(context);
                      _eventController.clear();
                      setState(() {});
                      return;
                    },
                    child: Text(&quot;OK&quot;))
              ],
            ),
          ),
          label: Text(&quot;Add label&quot;),
          icon: Icon(Icons.add),
          backgroundColor: Colors.green[600],
        ),
      );
    }
  }
  </code></pre>
  <p>And here is where I call the calendar screen:</p>
  <pre><code>import 'package:attendance_checker/screens/calender.dart';
  import 'package:attendance_checker/screens/help.dart';
  import 'package:attendance_checker/widgets/checkboxlist.dart';
  import 'package:attendance_checker/widgets/classinfo.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  class Home extends StatefulWidget {
    //const Home({ key }) : super(key: key);
  
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  
  class _HomeState extends State&lt;Home&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(
            title: Text(&quot;Attendance Checker&quot;),
            backgroundColor: Colors.green[700],
          ),
          drawer: Drawer(
            child: ListView(
              children: [
                DrawerHeader(
                  child: Text(
                    &quot;Drawer header&quot;,
                    style: TextStyle(fontSize: 24, color: Colors.white),
                  ),
                  decoration: BoxDecoration(color: Colors.green[700]),
                ),
                ListTile(
                  title: Text(&quot;Calender&quot;),
                  trailing: Icon(Icons.calendar_today_rounded),
                  onTap: () {
                    Navigator.pushReplacement(context,
                        MaterialPageRoute(builder: (context) =&gt; Calender()));
                  },
                ),
                ListTile(
                  title: Text(&quot;Help&quot;),
                  trailing: Icon(Icons.question_answer),
                  onTap: () {
                    Navigator.pushReplacement(
                        context, MaterialPageRoute(builder: (context) =&gt; Help()));
                  },
                )
              ],
            ),
          ),
          backgroundColor: Colors.green[400],
          body: Column(
            children: &lt;Widget&gt;[ClassInfo(), Checklist()],
          ));
    }
  }
  
  </code></pre>
  <p>I am not sure why this error is occurring, but it would be of great help if you could help me with it. Thanks in advance</p>