title: Flutter The method '[]' was called on null
body: <p>I am running my app and getting the error:</p>
  
  <p>"NoSuchMethodError: The Method '[ ]' was called on null. Receiver: null. Tried calling: ."</p>
  
  <pre><code>import 'dart:async';
  import 'dart:convert';
  import 'package:flutter/material.dart';
  
  import '../model/Lesson.dart';
  
  
  class MobileModeScreen extends StatefulWidget {
  
    @override
    _MobileModeScreenState createState() =&gt; _MobileModeScreenState();
  }
  
  
  class _MobileModeScreenState extends State&lt;MobileModeScreen&gt; {
  
    List&lt;Lesson&gt; _lesson;
  
  
    @override
    void initState() {
      super.initState();
      Future.delayed(Duration.zero,() {
        getLessonFromJSON(context);
      });
      print("lessonDescription: ${_lesson[0].lessonTitle}");
    }
  
    Future&lt;List&lt;Lesson&gt;&gt; getLessonFromJSON(BuildContext context) async {
      String jsonString = await DefaultAssetBundle.of(context).loadString("assets/lessons/lessons.json");
  
      return await Future.delayed(Duration.zero,() {
        List&lt;dynamic&gt; data = jsonDecode(jsonString);
        List&lt;Lesson&gt; lesson = data.map( (f) =&gt; Lesson.fromJSON(f) ).toList();
        _lesson = lesson;
        print("lessonDescription: ${_lesson[0].lessonTitle}");
        return _lesson;
      });
    }
  
  
    @override
    Widget build(BuildContext context) {
  
      return Directionality(
        textDirection: TextDirection.rtl,
        child: Scaffold(
          appBar: AppBar(
            title: Container(
              padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
              decoration: BoxDecoration(
                color: Color(0xffFFFFFF),
                border: Border.all(
                  color: Color(0xffF5ED02),
                  width: 3,
                ),
                borderRadius: BorderRadius.circular(25.0),
              ),
              child: Text("lessonDescription: ${_lesson[0].lessonTitle}",
                style: TextStyle(
                  //fontFamily: "Uthmani",
                  color: Color(0xff225587),
                ),
              ),
            ),
            centerTitle: true,
            backgroundColor: Color(0xff7F3F96),
          ),
  
          body: ListView(
            padding: const EdgeInsets.fromLTRB(5, 15, 5, 5),
            children: &lt;Widget&gt;[
            ],
          ),
          backgroundColor: Color(0xffF0E4F2),
        ),
      );
    }
  }
  
  </code></pre>
  
  <p>I'm not getting the error when I try to access the value from the <code>getLessonFromJSON</code> function, but outside of the function, it's not working at all.</p>
  
  <p>The error I get:</p>
  
  <pre><code>════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
  The following NoSuchMethodError was thrown building Builder:
  The method '[]' was called on null.
  Receiver: null
  Tried calling: [](0)
  
  The relevant error-causing widget was: 
    MaterialApp file:///home/hmalabeh/AndroidStudioProjects/Flutter/Bounyan/boynyan_final/lib/main.dart:12:12
  When the exception was thrown, this was the stack: 
  #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
  #1      _MobileModeScreenState.initState (package:boynyanfinal/screens/mobile_mode_screen.dart:26:40)
  #2      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
  #3      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  #4      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  ...
  </code></pre>
  
  <p>Can someone help please.</p>
  
  <p><strong>Update:</strong>
  I want to be able to use what I get from the function <code>getLessonFromJSON</code> in the <code>build</code> method like I'm using in the <code>Text</code> filed in the <code>AppBar</code></p>