title: Flutter localization - Text was called on Null
body: <p>I am trying to implement the localization for my Flutter app. But there is an error which is <code>The method 'text' was called on null. Receiver: null Tried calling: text("title")</code>.</p>
  
  <p>The problem comes from the language selector page where upon selecting the language. The title should have changed according to the language. Currently there are English and Chinese language.</p>
  
  <pre><code>import 'package:MyApp/services/AppTranslations.dart';
  import 'package:MyApp/services/Application.dart';
  import 'package:flutter/material.dart';
  
  
  class LanguageSelectorPage extends StatefulWidget {
    @override
    _LanguageSelectorPageState createState() =&gt; _LanguageSelectorPageState();
  }
  
  class _LanguageSelectorPageState extends State&lt;LanguageSelectorPage&gt; {
    //languagesList also moved to the Application class just like the languageCodesList
    static final List&lt;String&gt; languagesList = application.supportedLanguages;
    static final List&lt;String&gt; languageCodesList =
        application.supportedLanguagesCodes;
  
    final Map&lt;dynamic, dynamic&gt; languagesMap = {
      languagesList[0]: languageCodesList[0],
      languagesList[1]: languageCodesList[1],
    };
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(
            AppTranslations.of(context).text("title") //This is where the error come from
          ),
        ),
        body: _buildLanguagesList(),
      );
    }
  
    _buildLanguagesList() {
      return ListView.builder(
        itemCount: languagesList.length,
        itemBuilder: (context, index) {
          return _buildLanguageItem(languagesList[index]);
        },
      );
    }
  
    _buildLanguageItem(String language) {
      return InkWell(
        onTap: () {
          print(language);
          application.onLocaleChanged(Locale(languagesMap[language]));
        },
        child: Center(
          child: Padding(
            padding: const EdgeInsets.symmetric(vertical: 20.0),
            child: Text(
              language,
              style: TextStyle(
                fontSize: 24.0,
              ),
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>Inside my json file there is title.</p>
  
  <pre><code>{
      "title" : "Testing Title",
  }
  </code></pre>
  
  <p>This is my AppTranslations</p>
  
  <pre><code>import 'dart:async';
  import 'dart:convert';
  import 'dart:ui';
  
  import 'package:flutter/material.dart';
  import 'package:flutter/services.dart' show rootBundle;
  
  class AppTranslations {
    Locale locale;
    static Map&lt;dynamic, dynamic&gt; _localisedValues;
  
    AppTranslations(Locale locale) {
      this.locale = locale;
      _localisedValues = null;
    }
  
    static AppTranslations of(BuildContext context) {
      return Localizations.of&lt;AppTranslations&gt;(context, AppTranslations);
    }
  
    static Future&lt;AppTranslations&gt; load(Locale locale) async {
      AppTranslations appTranslations = AppTranslations(locale);
      String jsonContent = await rootBundle.loadString("assets/lang/${locale.languageCode}.json");
      _localisedValues = json.decode(jsonContent);
      return appTranslations;
    }
  
    get currentLanguage =&gt; locale.languageCode;
  
    String text(String key) {
      return _localisedValues[key] ?? "$key not found";
    }
  }
  </code></pre>