Skip to content

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

Open
@sstrickl

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    co.requestCommunity ask for documentationd.enhancementImproves docs with specific askdev.integrationRelates to platform integrationp1-highMajor but not urgent concern: Resolve in months. Update each month.t.performanceRelates to performance tuning and optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions