title: NetworkError.request(error: DioError [DioErrorType.other]: type 'Null' is not a subtype of type 'Object' | Flutter
body: <p>There is a project that opens without any errors on the first pc, and on the second the same project, the same flutter version, the same dependencies, but returns this error:</p>
  <pre><code>PlaceHolderClient.login(phoneNumber: +7 708 819 1447)
  I/flutter ( 4094): PlaceHolderClient.login(phoneNumber: +7 708 819 1447) =&gt; NetworkError.request(error: DioError [DioErrorType.other]: type 'Null' is not a subtype of type 'Object'
  I/flutter ( 4094): #0      DefaultHttpClientAdapter.fetch.&lt;anonymous closure&gt;
  package:dio/…/adapters/io_adapter.dart:55
  I/flutter ( 4094): #1      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:400:8)
  I/flutter ( 4094): #2      DefaultHttpClientAdapter.fetch
  package:dio/…/adapters/io_adapter.dart:55
  I/flutter ( 4094): &lt;asynchronous suspension&gt;
  I/flutter ( 4094): #3      DioMixin._dispatchRequest
  package:dio/src/dio_mixin.dart:632
  I/flutter ( 4094): &lt;asynchronous suspension&gt;
  I/flutter ( 4094): #4      DioMixin.fetch.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:dio/src/dio_mixin.dart)
  package:dio/src/dio_mixin.dart:1
  I/flutter ( 4094): &lt;asynchronous suspension&gt;
  I/flutter ( 4094): )
  I/flutter ( 4094): type 'Null' is not a subtype of type 'Object'
  E/flutter ( 4094): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
  
  
  </code></pre>
  <p><strong>I tried flutter upgrade, flutter downgrade vx.x.x
  (example v2.5.0)</strong></p>
  <p>This is my code:
  <strong>AuthService</strong></p>
  <pre><code>class AuthService {
    Future&lt;Result&lt;LoginResponseModel, NetworkError&gt;&gt; loginOrRegister({
      required String phoneNumber,
    }) async {
      return NetworkExecuter.execute&lt;LoginResponseModel, LoginResponseModel&gt;(
        route: PlaceHolderClient.login('+7 ' + phoneNumber),
        responseType: LoginResponseModel(),
      );
    }}
  </code></pre>
  <p><strong>Network Executer</strong></p>
  <pre><code>class NetworkExecuter {
    static UserData _userData = UserData();
    static bool debugMode = true;
  
    static showAlert(BuildContext? context, DioError error) {
      return showDialogCustom(
        context: context!,
        barrierDismissible: true,
        backgroundColor: Colors.black26,
        title: 'Ошибка',
        child: Container(
          padding: EdgeInsets.all(20),
          child: Center(
            child: Text(
              &quot;${error.response!.data[&quot;message&quot;]}&quot;,
              textAlign: TextAlign.center,
            ),
          ),
        ),
      );
    }
  
    static void handleError(DioError error, BuildContext buildContext) {
      print(error.message);
      switch (error.response!.statusCode) {
        case 402:
          _userData.setActivationRequired(true);
          Navigator.pushAndRemoveUntil(
            GlobalVariable.navState.currentContext!,
            MaterialPageRoute(
              builder: (context) =&gt; ActivationScreen(),
            ),
            (route) =&gt; false,
          );
          print(&quot;Payment required&quot;);
          break;
        case 403:
          showAlert(GlobalVariable.navState.currentContext!, error);
          break;
        case 422:
          // showAlert(GlobalVariable.navState.currentContext!, error);
          print(&quot;The data you have provided is invalid.&quot;);
          break;
        case 401:
          _userData.deleteToken();
          Navigator.pushAndRemoveUntil(
            GlobalVariable.navState.currentContext!,
            MaterialPageRoute(
              builder: (context) =&gt; LoginScreen(),
            ),
            (route) =&gt; false,
          );
          print(&quot;Unauthorized&quot;);
          break;
        case 404:
          showAlert(GlobalVariable.navState.currentContext!, error);
          print(&quot;Request not found.&quot;);
          break;
        case 500:
          showDialogCustom(
            context: GlobalVariable.navState.currentContext!,
            barrierDismissible: true,
            backgroundColor: Colors.black26,
            title: 'Ошибка',
            child: Container(
              padding: EdgeInsets.all(20),
              child: Center(
                child: Text(
                  &quot;Что то пошло не так c нашими серверами, свяжитесь с администратором чтобы проблема решилась быстрее!&quot;,
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          );
          print(
              &quot;There is something wrong with our servers, please report to the admin so it gets fixed.&quot;);
          break;
        default:
          showDialogCustom(
            context: GlobalVariable.navState.currentContext!,
            barrierDismissible: true,
            backgroundColor: Colors.black26,
            title: 'Ошибка',
            child: Container(
              padding: EdgeInsets.all(20),
              child: Center(
                child: Text(
                  &quot;Что то пошло не так!&quot;,
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          );
          print(&quot;Something went wrong.&quot;);
      }
    }
  
    static Future&lt;Result&lt;K, NetworkError&gt;&gt; execute&lt;T extends BaseNetworkModel, K&gt;(
        {required BaseClientGenerator route,
        T? responseType,
        NetworkOptions? options}) async {
      if (debugMode) print(route);
  
      // Check Network Connectivity
      if (await NetworkConnectivity.status) {
        try {
          var response =
              await NetworkCreator.shared.request(route: route, options: options);
          if (responseType != null) {
            var data = NetworkDecoder.shared
                .decode&lt;T, K&gt;(response: response, responseType: responseType);
            return Result.success(data);
          } else {
            return Result.success('' as K);
          }
  
          // NETWORK ERROR
        } on DioError catch (diorError) {
          if (debugMode)
            print(&quot;$route =&gt; ${NetworkError.request(error: diorError)}&quot;);
          handleError(diorError, GlobalVariable.navState.currentContext!);
          return Result.failure(NetworkError.request(error: diorError));
  
          // TYPE ERROR
        } on TypeError catch (e) {
          if (debugMode)
            print(&quot;$route =&gt; ${NetworkError.type(error: e.toString())}&quot;);
          return Result.failure(NetworkError.type(error: e.toString()));
        }
  
        // No Internet Connection
      } else {
        if (debugMode)
          print(NetworkError.connectivity(message: 'No Internet Connection'));
        showCustomSnackBar(
            context: GlobalVariable.navState.currentContext!,
            message: 'Интернет подключение отсутсвует');
        return Result.failure(
            NetworkError.connectivity(message: 'No Internet Connection'));
      }
    }
  }
  </code></pre>
  <p><strong>Network Creator</strong></p>
  <pre><code>class NetworkCreator {
    static var shared = NetworkCreator();
    Dio _client = Dio();
  
    Future&lt;Response&gt; request(
        {required BaseClientGenerator route, NetworkOptions? options}) async {
      return _client.fetch(
        RequestOptions(
          baseUrl: route.baseURL,
          method: route.method,
          path: route.path,
          headers: await route.header,
          queryParameters: route.queryParameters,
          data: route.body,
          sendTimeout: route.sendTimeout,
          receiveTimeout: route.sendTimeout,
          onReceiveProgress: options?.onReceiveProgress,
          validateStatus: (statusCode) =&gt; (statusCode! &gt;= HttpStatus.ok &amp;&amp;
              statusCode &lt;= HttpStatus.multipleChoices),
        ),
      );
    }
  }
  </code></pre>
  <p><strong>@freezed class PlaceHolderClient</strong>
  &quot;flutter pub run build_runner build --delete-conflicting-outputs&quot; runned on second pc</p>
  <pre><code>@freezed
  class PlaceHolderClient extends BaseClientGenerator with _$PlaceHolderClient {
    static final UserData _userData = UserData();
    // Routes
    const PlaceHolderClient._() : super();
    const factory PlaceHolderClient.login(String phoneNumber) = _Login;
    
  @override
    String get baseURL =&gt; &quot;url(its changed)&quot;;
  
  
  @override
    String get path {
      return this.when&lt;String&gt;(
        login: (String phoneNumber) =&gt; 'api/auth/login-or-register');
    }
  
  @override
    String get method {
      return this.maybeWhen&lt;String&gt;(
        orElse: () =&gt; 'GET',
        login: (String phoneNumber) =&gt; 'POST'); 
  //its post on postman(verified)
    }
  
  @override
    dynamic get body {
      return this.maybeWhen(
        login: (String phoneNumber) {
          return {
            'phone': phoneNumber,
            &quot;roles&quot;: [&quot;business&quot;, &quot;employee&quot;]
          };
        } );
    }
  }
  </code></pre>