Skip to main content

Platform

Trait Platform 

Source
pub trait Platform: Any {
Show 38 methods // Required methods fn target_platform(&self) -> TargetPlatform; fn request_frame(&self, view: ViewId); fn now(&self) -> Instant; fn dispatcher(&self) -> Arc<dyn Dispatcher> ⓘ; fn views(&self) -> Vec<ViewRef> ⓘ; fn view(&self, id: ViewId) -> Option<ViewRef>; // Provided methods fn request_view( &self, config: WindowConfig, initial_data: Option<String>, ) -> Result<RequestId, ViewError> { ... } fn locales(&self) -> Vec<Locale> { ... } fn set_application_locale(&self, locale: &Locale) { ... } fn platform_brightness(&self) -> Brightness { ... } fn default_route_name(&self) -> String { ... } fn initial_lifecycle_state(&self) -> Option<AppLifecycleState> { ... } fn font_source(&self) -> Option<Box<dyn FontSource>> { ... } fn default_font_families(&self) -> Vec<String> { ... } fn open_image_codec(&self, bytes: Arc<[u8]>) -> ImageCodecFuture { ... } fn import_pixels(&self, pixels: PixelBuffer) -> Option<Image> { ... } fn compositor(&self) -> Option<Arc<dyn Compositor>> { ... } fn vsync_waiter(&self) -> Option<Arc<dyn VsyncWaiter>> { ... } fn screens(&self) -> Option<&dyn Screens> { ... } fn clipboard(&self) -> Option<&dyn Clipboard> { ... } fn system_chrome(&self) -> Option<&dyn SystemChrome> { ... } fn haptics(&self) -> Option<&dyn Haptics> { ... } fn system_context_menu(&self) -> Option<&dyn SystemContextMenu> { ... } fn menu_bar(&self) -> Option<&dyn MenuBar> { ... } fn popup_menus(&self) -> Option<&dyn PopupMenus> { ... } fn tray_icons(&self) -> Option<&dyn TrayIcons> { ... } fn file_dialogs(&self) -> Option<&dyn FileDialogs> { ... } fn players(&self) -> Option<&dyn Players> { ... } fn cameras(&self) -> Option<&dyn Cameras> { ... } fn video_frame_readers(&self) -> Option<&dyn VideoFrameReaders> { ... } fn caption_settings(&self) -> Option<&dyn CaptionSettings> { ... } fn view_embedder(&self) -> Option<&dyn ViewEmbedder> { ... } fn dock_menu(&self) -> Option<&dyn DockMenu> { ... } fn text_services(&self) -> Option<&dyn TextServices> { ... } fn restoration(&self) -> Option<&dyn Restoration> { ... } fn app_exit(&self) -> Option<&dyn AppExit> { ... } fn opener(&self) -> Option<&dyn Opener> { ... } fn notifications(&self) -> Option<&dyn Notifications> { ... }
}
Expand description

The long-lived host object held by the application.

Implementations must queue requests and return. They must not synchronously re-enter the EmbedderClient while App is active.

A host may offer more than this interface — a picture from a buffer only its system has, a handle to its renderer. An app that knows its host reaches that through [downcast_ref](dyn Platform::downcast_ref); the interface itself names nothing of any one system.

Required Methods§

Source

fn target_platform(&self) -> TargetPlatform

Which host this is, for behaviour that follows platform convention (Flutter defaultTargetPlatform).

Required rather than defaulted: an embedder must say what it is, and a default would let one silently claim the wrong conventions.

Source

fn request_frame(&self, view: ViewId)

Asks for a frame of view: Flutter’s PlatformDispatcher.scheduleFrame, for one view.

view is in the next EmbedderClient::frame of the screen it is on once its window is in sight; the host holds the request while the window is minimized or occluded. Asked again before then, it is in that refresh once.

Source

fn now(&self) -> Instant

The host clock used for frame and timer timestamps.

Source

fn dispatcher(&self) -> Arc<dyn Dispatcher> ⓘ

The host’s threads, for waking the application or running work off the main thread: see Dispatcher.

Source

fn views(&self) -> Vec<ViewRef> ⓘ

Every view the app has now: those the platform gave it, such as a phone’s screen or an embedder’s views, and those it asked for. An app may run with none, as one on a desktop does until it asks.

Source

fn view(&self, id: ViewId) -> Option<ViewRef>

Looks up one of the app’s views.

Provided Methods§

Source

fn request_view( &self, config: WindowConfig, initial_data: Option<String>, ) -> Result<RequestId, ViewError>

Asks for a view in a window configured as config, carrying initial_data (View::initial_data), such as which screen to show. A desktop makes the window; a platform that gives the app its views and makes none, a phone or an embedder, answers ViewError::Unsupported. The view arrives later, through EmbedderClient::view_added, carrying the id answered here; a request that fails on the way is reported through EmbedderClient::view_request_failed.

Source

fn locales(&self) -> Vec<Locale>

The full system-reported supported locales of the device (Flutter PlatformDispatcher.locales), in order of preference; empty until the host reports them.

Source

fn set_application_locale(&self, locale: &Locale)

Tells the host which locale the application resolved to (Flutter PlatformDispatcher.setApplicationLocale); the default drops it.

Source

fn platform_brightness(&self) -> Brightness

The platform’s light/dark preference (Flutter PlatformDispatcher.platformBrightness).

Defaults to Brightness::Light, matching Flutter’s view configuration default. A live host that can see the OS theme overrides this.

Source

fn default_route_name(&self) -> String

The route the application was started with (Flutter PlatformDispatcher.defaultRouteName).

Defaults to "/", Flutter’s value for a host that was not asked to open a particular route; a host that receives a deep link answers it here.

Source

fn initial_lifecycle_state(&self) -> Option<AppLifecycleState>

The lifecycle state immediately after the application started (Flutter PlatformDispatcher.initialLifecycleState).

This property will not be updated as the lifecycle changes: a host reports each change through EmbedderClient::app_lifecycle_state_changed.

It is used to initialize SchedulerBinding::lifecycle_state at startup. Defaults to None, Flutter’s empty string: a host that has no state to report yet.

Source

fn font_source(&self) -> Option<Box<dyn FontSource>>

The platform’s own font lookup: faces by family name and by codepoint, the way Flutter’s engine asks the OS. None for a host without one; text then shapes only against fonts the application registers.

Source

fn default_font_families(&self) -> Vec<String>

Flutter’s txt::GetDefaultFontFamilies(): the families text uses when its style names none, first match first.

Defaults to the engine’s answer on the OS this build targets (default_font_families). A host that learns its OS at run time answers for that OS, and one whose fonts are not the OS’s, as a web page’s are not, answers its own.

Source

fn open_image_codec(&self, bytes: Arc<[u8]>) -> ImageCodecFuture

Open an encoded image, answering with a codec for its frames.

Flutter dart:ui instantiateImageCodec. The host decodes with whatever its platform provides and uploads each frame, so the framework never sees pixels and the set of readable formats is the platform’s rather than the framework’s.

The default answers a failure at once, so a host with no decoder leaves nobody waiting.

Source

fn import_pixels(&self, pixels: PixelBuffer) -> Option<Image>

An image from pixels the app already holds, with no codec in between: Flutter’s decodeImageFromPixels. None when the host has no renderer to put it on yet.

Source

fn compositor(&self) -> Option<Arc<dyn Compositor>>

The host’s compositor, where it has one: composition layers shown beside the framework’s picture. None on the web, on X11, on the inert host, and on an embedder that chose not to have one.

Source

fn vsync_waiter(&self) -> Option<Arc<dyn VsyncWaiter>>

Flutter’s VsyncWaiter, for any screen: the refreshes the host draws the framework’s frames at, for a producer that paces by them, as a composition layer’s does. None for a host without screen ticks.

Source

fn screens(&self) -> Option<&dyn Screens>

The screens the app’s views are on, and where the pointer is on them (Flutter PlatformDispatcher.displays), or None where the host has none to report. Every host with screens answers, a phone with its one included; a view’s metrics name the screen it is on, and a host that hears the screens change says so through EmbedderClient::screens_changed.

Source

fn clipboard(&self) -> Option<&dyn Clipboard>

The system clipboard, or None where the host has none.

Source

fn system_chrome(&self) -> Option<&dyn SystemChrome>

The system UI drawn around the app, or None where the host has none.

Source

fn haptics(&self) -> Option<&dyn Haptics>

Haptic feedback on the device, or None where the host has none.

Source

fn system_context_menu(&self) -> Option<&dyn SystemContextMenu>

The system’s own menu over a text selection, or None where the host has none.

Source

fn menu_bar(&self) -> Option<&dyn MenuBar>

The app’s menu bar, or None where the system has none and the app draws its own, as on Windows, Linux and phones (menus).

Source

fn popup_menus(&self) -> Option<&dyn PopupMenus>

Menus the system opens at a point in a view, or None where the system has none and the framework draws them.

Source

fn tray_icons(&self) -> Option<&dyn TrayIcons>

The app’s icons in the system’s tray, or None where the system has no tray.

Source

fn file_dialogs(&self) -> Option<&dyn FileDialogs>

The system’s file dialogs, or None where the system has none.

Source

fn players(&self) -> Option<&dyn Players>

The system’s media players, or None where the host has none.

Source

fn cameras(&self) -> Option<&dyn Cameras>

The system’s cameras, or None where the host has none. A host with cameras answers one with none attached as an empty list.

Source

fn video_frame_readers(&self) -> Option<&dyn VideoFrameReaders>

The system’s frame readers, which a player or a camera hands its frames to, or None where the system hands out no frames.

Source

fn caption_settings(&self) -> Option<&dyn CaptionSettings>

The user’s caption settings, or None where the system keeps none, as Linux and the web keep none.

Source

fn view_embedder(&self) -> Option<&dyn ViewEmbedder>

What the app embeds views of its own with, on layers it makes and places, or None where the host cannot draw a view into such a layer: everywhere but macOS today.

Source

fn dock_menu(&self) -> Option<&dyn DockMenu>

The menu of the app’s Dock icon, or None where the system has no Dock.

Source

fn text_services(&self) -> Option<&dyn TextServices>

The system services a selection toolbar offers, or None where the host has none.

Source

fn restoration(&self) -> Option<&dyn Restoration>

Application state kept across relaunches, or None where the host has none.

Source

fn app_exit(&self) -> Option<&dyn AppExit>

Quitting at the application’s own request, or None where the host cannot quit itself: a phone, a browser tab.

Source

fn opener(&self) -> Option<&dyn Opener>

The system’s way to open links and files in other apps, or None where it has none.

Source

fn notifications(&self) -> Option<&dyn Notifications>

The system’s notifications, or None where it has none for the app.

Implementations§

Source§

impl dyn Platform

Source

pub fn downcast_ref<T: Platform>(&self) -> Option<&T>

The host as its own type, for what it offers beyond the interface.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§