-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Docs for merging between Options
and BaseOptions
are not clear
#2194
Comments
Pseudo: const baseDartUrl = 'https://dart.dev';
const baseFlutterUrl = 'https://flutter.dev';
void main() async {
final dio = Dio(BaseOptions(baseUrl: baseDartUrl));
final requestWithDart = await dio.get('/');
final requestWithFlutter = await dio.get('$baseFlutterUrl/');
} |
I have a genetic method that makes requests to a complete url variable. I remember passing the variable to Also, how do you change the |
Would be good if you could provide a reproducible case.
Each request can specify |
But that option I am proving is a new option, so wouldn't it override the values in my default option I used for constructing the dio instance? |
Of course |
But I want that request to carry all the options provided in the base options, only overriding the ones I need to change, not all of them. |
I'm wondering if you really tried to use Given the above conversation, I think your usage might be invalid somehow. I cannot provide suggestions unless there is an actual problem with options, and please provide a reproducible example to explain your demand. |
@AlexV525 I tested and indeed it worked, I think the docs got me confused, the docs say:
The word "override" implies that all my Base Options are gone. I thought I would have to recreate all the configurations myself, from both options objects. I would recommend some more details to ba added to this doc, explaining the options objects are merged, where the items defined inside the new options object will override the fields defined inside the base options. |
I'm not sure it implies the idea you've mentioned. No default values were given in the |
I know that's how the code looks like, but reading the docs that's not clear. The internal code could be easily overriding things with nulls. |
Override means substitute, merge means combine both into one. |
fetch
Options
and BaseOptions
are not clear
Yea, I can see that this might be confusing. Feel free to create a PR to update the documentation! |
Request Statement
I want to reuse my
dio
instance, to take advantage of all the interceptors, timeouts and other things that were configured inside it. I have one HTTP GET request that needs to be done in another base URL tough, so I need to modify the base URL and theresponseType
. I tried this, but it doesn't work:The idea was to create a new
options
object that has all the current options of mydio
instance, just changing thebaseUrl
andresponseType
. This doesn't work becausecompose
returns aRequestOptions
andget
needs anOptions
object.The kinds of objects that
dio
creates limits the flexibility of the package and makes the API kinda confuse.The only way I managed to get this to work was by doing:
Solution Brainstorm
No response
The text was updated successfully, but these errors were encountered: