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

Add information about how platform-specific Dart code can be guarded so that it is appropriately tree-shaken in release applications #11666

Open
1 task
sstrickl opened this issue Feb 3, 2025 · 0 comments
Labels
co.request Community ask for documentation d.enhancement Improves docs with specific ask dev.integration Relates to platform integration p1-high Major but not urgent concern: Resolve in months. Update each month. t.performance Relates to performance tuning and optimization

Comments

@sstrickl
Copy link

sstrickl commented Feb 3, 2025

What information needs to be added?

Would it be possible to say somewhere that code guarded with checks against defaultTargetPlatform, e.g.,

if (defaultTargetPlatform == TargetPlatform.windows) {
  /* Windows-specific code here */ 
}

or

switch (defaultTargetPlatform) {
  case TargetPlatform.windows:
    /* Windows-specific code here */
    break;
  ...
}

are appropriately tree-shaken in release builds of Flutter applications (and so dependencies used only in code guarded by such checks should also be tree-shaken, etc.)?

Where should this new content appear?

Currently it looks like the only examples of code using defaultTargetPlatform are in https://docs.flutter.dev/platform-integration/macos/platform-views and https://docs.flutter.dev/platform-integration/ios/platform-views, and https://docs.flutter.dev/platform-integration/platform-channels only mentions defaultTargetPlatform in a sidebar, so I'm unsure if those are the right places or not, or if this should be relegated to the defaultTargetPlatform/TargetPlatform API docs.

See dart-lang/sdk#31969 (comment) for the original request, and see flutter/flutter#14233 (comment) for more background. Let me know if there's anything I can do to help, or if there's some place I should file this instead. Thanks!

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@sstrickl sstrickl added the co.request Community ask for documentation label Feb 3, 2025
@parlough parlough added d.enhancement Improves docs with specific ask p1-high Major but not urgent concern: Resolve in months. Update each month. t.performance Relates to performance tuning and optimization dev.integration Relates to platform integration labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
co.request Community ask for documentation d.enhancement Improves docs with specific ask dev.integration Relates to platform integration p1-high Major but not urgent concern: Resolve in months. Update each month. t.performance Relates to performance tuning and optimization
Projects
None yet
Development

No branches or pull requests

2 participants