dart-lang / dart-lang/language
Platform (iOS, Android, etc.) should be a useable condition for conditional imports
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I have multiple platform-specific implementations of an HTTP client and I would like to select the appropriate one for the platform e.g. to use one based on NSURLSession on iOS, cronet on Android, etc.
In C++, I would use preprocessor macros to solve this issue e.g.
```C++
HttpClient *client;
#ifdef IOS
#include
client = new NSURLAdapter();
#elif ...
```
In Python, I would do the configuration at runtime e.g.
```python
import platform
client: HttpClient
if platform.system() == "Windows":
import whatever
client = whatever.WindowsClient()
elif ...
```
In Dart, I don't know how to solve this problem except in the narrow case of differentiating between web and non-web (using conditional imports).
Contributor guide
Research direction
No files, tests, or entry points are named. Start by reviewing the conditional-import behavior described in this issue and the platform-specific examples, then define the language behavior and acceptance criteria for selecting implementations by platform.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100