This post shows you one strategy to design a high-level interface for functionality that exists in both dart:io and dart:html. While the Dart team has the concept of configurability on their radar, not much concrete action has happened. In the meantime, try this strategy and you too can experiment with unifying interfaces and APIs. Code reuse FTW!
(This post was inspired by Mark Bennett's original question who is trying to build a more unified Web Socket interface.)
Step 1: Create a library and an interface
Design the interface that unifies something from dart:html and dart:io.
Step 2: Implement the interface for dart:html
In another library, implement the interface with dart:html:
Step 3: Implement the interface for dart:io
In another library, implement the interface with dart:io.
Step 4: Package it up
All of the previous code can go into the same pub package.
Pick a library to use
The consumer of your pub package must decide which library to import. For example, a dart:io app might look like this:
Hope that helps! All the code for this example is found at Github.