Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add values to dio data inside interceptor #2114

Closed
centralizer opened this issue Feb 19, 2024 · 1 comment
Closed

Cannot add values to dio data inside interceptor #2114

centralizer opened this issue Feb 19, 2024 · 1 comment

Comments

@centralizer
Copy link

Package

dio

Version

5.2.1+1

Operating-System

iOS

Output of flutter doctor -v

No response

Dart Version

No response

Steps to Reproduce

I am attempting to add a value channelId to the data object inside the interceptor. I have tried everything and cannot get this to work. The first if check adds the value to requests that do not have a data object. That works fine. The second if check is supposed to add the value to existing data objects and I cannot get this to work. I have included screenshots of the data print and runtimeType result, including error. I really would appreciate some help. This really seems like something that should be trivial.

  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    final role = storage.readRole();

    if (role?.id != null && options.data == null) {
      options.data = {"channelId": role?.id};
    }

    if (role?.id != null && options.data != null) {
      options.data["channelId"] = role?.id;
    }

    return super.onRequest(options, handler);
  }
Screenshot 2024-02-19 at 10 30 58 AM

Expected Result

The channelId key/value would be added to the data object.

Actual Result

Resulting error.

Screenshot 2024-02-19 at 10 30 58 AM
@centralizer centralizer added h: need triage This issue needs to be categorized s: bug Something isn't working labels Feb 19, 2024
@AlexV525
Copy link
Member

Tests in https://github.com/cfug/dio/blob/main/dio/test/interceptor_test.dart are all running well. Perhaps you didn't add the interceptor to your instance or the data was renormalized by another interceptor?

@AlexV525 AlexV525 added i: no useful information and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Mar 3, 2024
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants