Below is a simple class which i want to wrap dio class is singleton, as i enabled analyzer i get this error:
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'.
my 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;
}
}
how can i resolve this problem for analyzer ?