instance property

PlatformDispatcher instance

The PlatformDispatcher singleton.

Consider avoiding static references to this singleton through PlatformDispatcher.instance and instead prefer using a binding for dependency resolution such as WidgetsBinding.instance.platformDispatcher.

Static access of this object means that Flutter has few, if any options to fake or mock the given object in tests. Even in cases where Dart offers special language constructs to forcefully shadow such properties, those mechanisms would only be reasonable for tests and they would not be reasonable for a future of Flutter where we legitimately want to select an appropriate implementation at runtime.

The only place that WidgetsBinding.instance.platformDispatcher is inappropriate is if access to these APIs is required before the binding is initialized by invoking runApp() or WidgetsFlutterBinding.instance.ensureInitialized(). In that case, it is necessary (though unfortunate) to use the PlatformDispatcher.instance object statically.


static PlatformDispatcher get instance => _instance;