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

The name 'Response' is defined in the libraries 'package:dio/src/response.dart (via package:dio/dio.dart)' and 'package:get/get_connect/http/src/response/response.dart'. #994

Closed
ghenry opened this issue Jan 8, 2021 · 18 comments
Assignees
Labels
Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue

Comments

@ghenry
Copy link

ghenry commented Jan 8, 2021

Describe the bug
Should there be a conflict here?

Reproduction code
Test the following

example:

import 'package:dio/dio.dart';
import 'package:logger/logger.dart';
import 'package:get/get.dart';

final ourApi = Dio();
final Logger logger = Get.find<LoggerController>().logger;

final handleExpiredTokenInterceptor =
    InterceptorsWrapper(onError: (error) async {
  if (error.response?.statusCode == 403 || error.response?.statusCode == 401) {
    logger.d('Access Token not active. Getting a new one via a Refresh Token.');
    AuthController c = Get.find();
    final accessToken = await c.refreshMyToken();
    return _retry(error.request, accessToken);
  }
  return error.response;
});

// ISSUE IS HERE
Future<Response<dynamic>> _retry(
    RequestOptions requestOptions, String accessToken) async {
  final options = new Options(
    method: requestOptions.method,
    headers: requestOptions.headers,
  );
  options.headers['Authorization'] = 'Bearer $accessToken';
  logger.d('Sending request again with new token');
  return ourApi.request<dynamic>(requestOptions.path,
      data: requestOptions.data,
      queryParameters: requestOptions.queryParameters,
      options: options);
}

To Reproduce
Not needed

Expected behavior
No conflict.

Flutter Version:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, 1.26.0-1.0.pre, on Microsoft Windows [Version 10.0.19042.685], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.3)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.52.1)
[√] Connected device (1 available)

Getx Version:
3.23.1

Describe on which device you found the bug:
Window Desktop

Minimal reproduce code
Not needed

Workaround:

If I do:

import 'package:get/get.dart' as GET;

and then something like:

final Logger logger = GET.Get.find<LoggerController>().logger;

all is well.

@eduardoflorence
Copy link
Collaborator

eduardoflorence commented Jan 8, 2021

Do:

import 'package:get/get.dart' hide Response;

@eduardoflorence eduardoflorence added the Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue label Jan 9, 2021
@ghenry
Copy link
Author

ghenry commented Jan 9, 2021

And if I was using GetConnect?

@eduardoflorence
Copy link
Collaborator

import 'package:dio/dio.dart‘ hide Response;

@ghenry ghenry closed this as completed Jan 9, 2021
@ghenry
Copy link
Author

ghenry commented Jan 9, 2021

Thanks

@itwondersteam
Copy link

@eduardoflorence Thanks for the great package! Basically this is the most loved flutter package we use so far, well done!

Regarding this issue, just curious would it be better for user to import separately if they need to use the GetResponse? as Dio is quite a common and popular package.

@eduardoflorence
Copy link
Collaborator

Hi @itwondersteam, I'm glad you like Getx, I love him too. I am not the owner of this package, I am just a contributor. Jonny has already explained in another issue about the reason for incorporating GetConnect, please take a look at it:
#850

@itwondersteam
Copy link

itwondersteam commented Jan 12, 2021

@eduardoflorence thanks for the pointer, and it is great to see where Getx is heading to. The idea of integrate everything in one place without it breaking due to incompatibility is just awesome!

Having said that, I still feel it might be better to import Response separately, for the reason

  • many projects might have already using Dio before Getx
  • auto import is easy (when we need to use GetConnect, is just a click away)
  • putting hide Response in hundred of dart files (where Dio is being used) is no fun, and you will not expect to have error until you compile the program
  • so it is better to name common term with prefix, e.g.XResponse or GetResponse to avoid such circumstances.

Just my 2 cents, but I understand that there might be other considerations from getx project point of view that I have not thought of...

Still, Getx is damn sexy! Well done Sir, @jonataslaw

@imamabdulazis
Copy link

import 'package:dio/dio.dart‘ hide Response;

Thanks dude.

@fer-ri
Copy link
Contributor

fer-ri commented Feb 18, 2021

Since I'm using Response from Dio for type hinting, then I prefer to hide Response from Get with this

import 'package:get/get.dart' hide Response;

@imamabdulazis
Copy link

Since I'm using Response from Dio for type hinting, then I prefer to hide Response from Get with this

import 'package:get/get.dart' hide Response;

sorry to say, but it was answered in previous comment 😂

@fer-ri
Copy link
Contributor

fer-ri commented Feb 18, 2021

Since I'm using Response from Dio for type hinting, then I prefer to hide Response from Get with this

import 'package:get/get.dart' hide Response;

sorry to say, but it was answered in previous comment

It's different actually. The previous hide from Dio, but mine hide from Get

@imamabdulazis
Copy link

Do:

import 'package:get/get.dart' hide Response;

@ghenry this is previous answer.

@fer-ri
Copy link
Contributor

fer-ri commented Feb 18, 2021

Ah yes, sorry, missed that 👍

@aadilansari
Copy link

You have to add prefix to the Response when you are using get library.
add one more line for dio and give name to it
import 'package:dio/dio.dart' as DIO;
now add it Response,
DIO.Response

@dimassyaiful
Copy link

Do:

import 'package:get/get.dart' hide Response;

THANKSSSS ...

@shylendramadda
Copy link

You have to add prefix to the Response when you are using get library. add one more line for dio and give name to it import 'package:dio/dio.dart' as DIO; now add it Response, DIO.Response

Thanks this worked in my case I got this error:
The name 'FormData' is defined in the libraries 'package:dio/src/form_data.dart (via package:dio/dio.dart)' and 'package:get/get_connect/http/src/multipart/form_data.dart'. Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.

Then I fixed it with the help of this comment:

import 'package:dio/dio.dart' as dio;
var data = dio.FormData.fromMap({
'mobile': phoneNumber,
});

@AnghamReg
Copy link

You have to add prefix to the Response when you are using get library. add one more line for dio and give name to it import 'package:dio/dio.dart' as DIO; now add it Response, DIO.Response

Thanks this worked in my case I got this error: The name 'FormData' is defined in the libraries 'package:dio/src/form_data.dart (via package:dio/dio.dart)' and 'package:get/get_connect/http/src/multipart/form_data.dart'. Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.

Then I fixed it with the help of this comment:

import 'package:dio/dio.dart' as dio; var data = dio.FormData.fromMap({ 'mobile': phoneNumber, });

Thank you !

@arthikrishh
Copy link

Try this

import 'package:dio/dio.dart' hide Response, FormData, MultipartFile;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue
Projects
None yet
Development

No branches or pull requests