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

[ Change some URLs at execution ] #1994

Closed
Gobmichet opened this issue Oct 12, 2023 · 3 comments
Closed

[ Change some URLs at execution ] #1994

Gobmichet opened this issue Oct 12, 2023 · 3 comments

Comments

@Gobmichet
Copy link

Request Statement

Hi,
First of all, thanks for the job !

I did a "feature" post but maybe you'll tell me there's a way to achieve this that i'm not aware of...

Like said in the title i'd like to be able to change URLs for WS calls at execution...

The real situation is this :

Got on app that works well

  • Other entities/enterprises would like to use it but their backends would obviously be at different URLs
  • We'd like to be able at the user's login, to change some URLs in order to hit the right backends...
  • The problem is the " .g.dart" that are generated.

How to achieve this please ?

Or have you got a workaround for such a situation !?

Thanks in advance.

Solution Brainstorm

No response

@Gobmichet Gobmichet added the s: feature This issue indicates a feature request label Oct 12, 2023
@AlexV525
Copy link
Member

I'm not sure what's the relationship between your .gs and Dio.

A minimal example to explain your demand would be appreciatable, or the issue is not actionable at the moment.

@AlexV525 AlexV525 added the h: need more info Further information is requested label Oct 12, 2023
@kuhnroyal
Copy link
Member

You can always pass an absolute URL to all dio calls.
You can create a new instance of dio with the changed base URL.

@PuzzleTakX
Copy link

It sounds like you want to dynamically change the URLs for WebSocket (WS) calls in your Flutter app based on user login. Here's a solution brainstorm to address this situation:

  1. Configuration Management:
    Create a configuration management system that allows you to store different backend URLs for different users or enterprises. This could be as simple as a configuration file or a database.

  2. Dynamic URL Selection:
    Upon user login, retrieve the correct backend URL from the configuration based on the user's profile or enterprise. You can use shared preferences, local storage, or a central configuration service to store and fetch the URL.

  3. URL Injection:
    Use the selected URL when making WebSocket calls. Instead of hardcoding the URL in your WebSocket code, inject the selected URL from your configuration management system.

  4. Conditional Imports:
    If you're generating Dart files with .g.dart extensions that contain URL constants, consider using conditional imports. Depending on the selected URL, import the appropriate file that contains the corresponding URLs. This allows you to switch between URLs without modifying your code.

  5. Flutter Environment Variables:
    You can also make use of environment variables or build flavors in Flutter. Define different environment configurations for each enterprise, and use the appropriate configuration during the build.

  6. Code Generation and Code Generation Hooks:
    If you're using code generation tools like json_serializable or chopper, explore code generation hooks to customize code generation based on your selected URL. This can help ensure that generated code uses the correct URL.

  7. Testing and Validation:
    Thoroughly test the app with different URLs to ensure that it works correctly for each enterprise. Consider setting up automated tests for each configuration.

  8. User Interface:
    Provide a user interface for users to change the URL or select the enterprise-specific URL. This should be user-friendly and clearly indicate the change in the backend URL.

Remember to follow best practices for managing configurations and ensure that sensitive information, such as API keys or secrets, is handled securely. This solution should help you adapt your app to work with different backend URLs for different entities or enterprises.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
@AlexV525 AlexV525 added i: no useful information and removed s: feature This issue indicates a feature request h: need more info Further information is requested labels Oct 16, 2023
@Gobmichet
Copy link
Author

Gobmichet commented Oct 18, 2023

Hi, ok my bad i'm using Retrofit over Dio and that's Retrofit that adds the .g.dart...

I made the same post to retrofit repo but if you can help, any help would be apprciated ^^

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

4 participants