MVP

As in MVP there is Presenter and View

Example

Presenter implements logic and returns the result through subject

    class SamplePresenter extends Presenter<SampleView> {
    
      SamplePresenter(SampleView view) : super(view) {
        view.counter.add(CounterState(count));
      }
    }
    
    mixin SampleView implements View {
      final counter = BehaviorSubject<CounterState>();
    
      @override
      close() {
        counter.close();
      }
    }
    

state implements view and has presenter

    class _SampleWidgetState
        extends StateWithPresenter<SampleWidget, SamplePresenter> with SampleView {
      @override
      SamplePresenter createPresenter() {
        return SamplePresenter(this);
      }
    }

There is also a mechanism for unsubscribing from the result from future or stream

Example Cancelable

    Future future;
    CancelableFuture cancelableFuture = CancelableFuture(future);
    cancelableFuture.then((value) {
      print(value);
    });
    cancelableFuture.cancelable.cancel();

The presenter has futures in map, that will be canceled if the view is closed or if future with the same key

You can add your requests in this map using the method cancelable

    cancelable(cancelKey,Future.delayed(Duration(seconds: 1)))
    .then((_) {})

Libraries

cancelable
cancelable_future
cancelable_stream
mpv
presenter
stream_widget
view
with_presenter

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.