Skip to content

How to fix compilation errors when not building for web? #317

Open
@gdurandrexel

Description

@gdurandrexel

I have a flutter app that should support mobile and web, but compilation fails when building for mobile with errors such as "Dart library 'dart:js_interop' is not available on this platform.".

In my code I import dart:io and web/web and use kIsWeb to call IO methods or web methods.

When compiling for web, importing dart:io does not cause any problem.

I've read about creating a stub file and importing io or web implementations, but my code is sprinkled with kIsWeb checks with tiny bits of code.
Is it really the only way to make this work? How come importing dart:io is fine but web/web is not?
Could this package provide a stub so we can write something like this:

import 'package:web/web_stub.dart' as web
  if (dart.library.js_interop) 'package:web/web.dart';

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions