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

Conditional imports is not covered in the language tour #1569

Closed
jonasfj opened this issue May 6, 2019 · 14 comments · Fixed by #2079
Closed

Conditional imports is not covered in the language tour #1569

jonasfj opened this issue May 6, 2019 · 14 comments · Fixed by #2079
Assignees
Labels
a.language Relates to the Dart language tour e1-hours Can complete in < 8 hours of normal, not dedicated, work p1-high Major but not urgent concern: Resolve in months. Update each month.

Comments

@jonasfj
Copy link
Member

jonasfj commented May 6, 2019

Page URL: https://www.dartlang.org/guides/language/language-tour
Page source: src/_guides/language/language-tour.md.

Conditional imports is not covered by the language tour. Conditional imports are usually done like:

import 'src/impl_stub.dart'  // stub implementation
    if (dart.library.io) 'src/impl_io.dart' // implementation using dart:io
    if (dart.library.html) 'src/impl_web.dart'; // implementation using dart:html|js

It would be nice to cover this in the language tour as the specification is hard to read. A few good examples of what you can make conditions on would also be useful, as this is not obvious.

@LRN, please correct me if this is not a stable language feature?

@jonasfj jonasfj added a.language Relates to the Dart language tour docs labels May 6, 2019
@kwalrath kwalrath added e1-hours Can complete in < 8 hours of normal, not dedicated, work act.wait-for-customer Needs response from customer p1-high Major but not urgent concern: Resolve in months. Update each month. labels May 6, 2019
@mit-mit
Copy link
Member

mit-mit commented Aug 6, 2019

@kwalrath what the needs-info part? From the language teams perspective this is a fully supported feature.

@kwalrath
Copy link
Contributor

kwalrath commented Aug 6, 2019

I think I was waiting to hear if this was a stable feature.

@jonasfj
Copy link
Member Author

jonasfj commented Aug 6, 2019

Hmm, I might have pinged the wrong LRN, sorry..

@lrhn, is this something that is stable, and can we encourage developers to adopt it?

@mit-mit
Copy link
Member

mit-mit commented Aug 7, 2019

Related issue (where I just commited to getting more info from lang. team): #1750

@rodydavis
Copy link
Contributor

here is an example project that i use this with for desktop, mobile and web: https://github.com/AppleEducate/moor_shared

@rydmike
Copy link

rydmike commented Sep 17, 2019

Great example @AppleEducate, it solved my issue in flutter/flutter#40488

@rodydavis
Copy link
Contributor

rodydavis commented Sep 17, 2019

No problem 😎💪🏻

@leafpetersen
Copy link
Member

This is a shipped and specified feature, and there are no current plans to deprecate it.

@kwalrath kwalrath removed the act.wait-for-customer Needs response from customer label Sep 19, 2019
@kwalrath kwalrath self-assigned this Nov 4, 2019
@SaadArdati
Copy link

SaadArdati commented Nov 10, 2019

This still requires documentation. I'm finding problems with conditional imports.

This is my firebase_access.dart class

export 'unsupported_firebase.dart' if (dart.library.io) 'firebase_mobile.dart' if (dart.library.html) 'firebase_web.dart';

This class works for firebase_mobile.dart but does NOT work for firebase_web.dart.
I don't know why, I tried printing a line for each, it prints for firebase_mobile on mobile, does NOT print for firebase_web.

This is firebase_web.dart (using the firebase_web plugin) :
image
In the following code, we have

    print("firebase web init");

while in firebase_mobile.dart (using the official firebase plugin):
image
we have

    print("firebase mobile init");

Now in my main class, I'm doing the following:
image

Note the import firebase_access.dart

In both mobile and web, it prints beginning init
However on mobile, it prints firebase mobile init after while on web, it does NOT print firebsae web init

I'm unsure why. The lack of documentation is problem.

EDIT: Also want to mention: breakpoint obviously isn't running in the firebase_web.dart class.

Here's my class hierarchy as evidence that it's not a spelling error:
image

@mit-mit
Copy link
Member

mit-mit commented Nov 11, 2019

cc @lrhn

@lrhn
Copy link
Member

lrhn commented Nov 11, 2019

I see no problem with the conditional export. My guess is that the problem lies elsewhere.
If the program compiles, then it has exported some version of the library.
Does the unsupported_firebase.dart file contain any prints, so you can see if it picks that incorrectly?

@SaadArdati
Copy link

SaadArdati commented Nov 11, 2019

@lrhn Yes it does:

image

It's never printed.

@SaadArdati
Copy link

Should I open a new issue for this?

@mit-mit
Copy link
Member

mit-mit commented Nov 13, 2019

Yes, please open a new issue (the present bug tracked documentation), with the smallest set of repro steps you have. Please open it in the SDK repo: https://github.com/dart-lang/sdk/issues

@atsansone atsansone removed the docs label Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.language Relates to the Dart language tour e1-hours Can complete in < 8 hours of normal, not dedicated, work p1-high Major but not urgent concern: Resolve in months. Update each month.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants