title: Flutter making singleton class and getting Non-nullable instance field error
body: <p>Below is a simple class which i want to wrap <code>dio</code> class is singleton, as i enabled <code>analyzer</code> i get this error:</p>
  <blockquote>
  <p>Non-nullable instance field '_instance' must be initialized.
  (Documentation)  Try adding an initializer expression, or add a field
  initializer in this constructor, or mark it 'late'.</p>
  </blockquote>
  <p>my code:</p>
  <pre class="lang-dart prettyprint-override"><code>const baseApiUrl = 'http://localhost';
  
  class BaseDio {
    BaseDio._();
  
    static BaseDio _instance;
  
    static BaseDio getInstance() {
      return _instance;
    }
  
    final cacheManager = DioCacheManager(CacheConfig(baseUrl: baseApiUrl));
    final BaseOptions options = BaseOptions(
      connectTimeout: 20000,
      receiveTimeout: 30000,
    );
  
    Dio getDio() {
      final dio = Dio(options)
        ..interceptors.addAll(
          [
  
            PrettyDioLogger(
              requestHeader: true,
              requestBody: true,
              responseBody: true,
              responseHeader: false,
              compact: false,
            ),
  
            cacheManager.interceptor as Interceptor,
            LogInterceptor(responseBody: false),
          ],
        );
  
      return dio;
    }
  }
  </code></pre>
  <p>how can i resolve this problem for <code>analyzer</code> ?</p>