title: How to import Dart file or package dependent on Flutter platform?
body: <p>My goal is to import platform-specific code only on the respective platform. One use case is e.g. if the <code>dart:html</code> package is used in the imported file which isn't available on iOS. Another example for platform-specific Dart code: XHR HTTP request (only available in browser) vs. other HTTP client implementation.</p>
  
  <p>Previous, failed attempts:</p>
  
  <p>1)</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'specific_to_web.dart' if (dart.library.html) '';
  </code></pre>
  
  <p>2)</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/foundation.dart' show kIsWeb;
  import 'specific_to_web.dart' if (kIsWeb) '';
  </code></pre>
  
  <p>3)</p>
  
  <p>In the file I'm importing:</p>
  
  <pre class="lang-dart prettyprint-override"><code>export 'api_channel_grpc_web.dart'
      if (dart.library.html) 'api_channel_grpc_raw.dart';
  </code></pre>
  
  <hr>
  
  <p>This is also mentioned in Flutter issue <a href="https://github.com/flutter/flutter/issues/39998" rel="nofollow noreferrer">Dart SDK libraries and Flutter for web</a>.</p>