I have a problem with Flutter in the dio library (dio: ^4.0.0).
import 'package:dio/dio.dart';
class DioHelper {
static Dio dio;
static init() {
dio = Dio(
BaseOptions(
baseUrl: 'https://192.168.0.23/',
receiveDataWhenStatusError: true,
),
);
}
}
If you hover over 'dio' you'll see the error. I'm guessing the error is The non-nullable variable 'dio' must be initialized. Try adding an initializer expression.
.
Which means you either need to initialize dio at the point of declaring it, or in your case, since you're initializing it in your init method, you need to add the late
modifier. See here for more info.
class DioHelper
{
static late Dio dio;
static init()
{
dio = Dio(
BaseOptions(
baseUrl: 'https://192.168.0.23/',
receiveDataWhenStatusError: true,
),
);
}
}