pub trait Platform: Any {
Show 53 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 time_zone_offset(&self, seconds_since_epoch: i64) -> SignedDuration { ... }
fn time_zone_name(&self, seconds_since_epoch: i64) -> String { ... }
fn briefly_show_password(&self) -> bool { ... }
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 picture_to_image_sync(
&self,
picture: &Picture,
width: u32,
height: u32,
) -> Option<Image> { ... }
fn read_image_pixels(&self, image: &Image) -> ImageFuture<PixelBuffer> { ... }
fn import_video_frame(&self, frame: &dyn VideoFrame) -> Option<Image> { ... }
fn import_hardware_buffer(
&self,
buffer: &dyn HardwareBuffer,
) -> Option<Image> { ... }
fn import_texture(
&self,
buffer: &dyn HardwareBuffer,
device: &Device,
) -> Option<Texture> { ... }
fn import_planes(
&self,
buffer: &dyn HardwareBuffer,
device: &Device,
) -> Option<Vec<TextureView>> { ... }
fn gpu_id(&self, device: &Device) -> Option<GpuId> { ... }
fn gpu(&self, id: Option<GpuId>) -> Option<Rc<dyn SystemGpu>> { ... }
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 http(&self) -> Option<&dyn HttpClient> { ... }
fn files(&self) -> Option<&dyn Files> { ... }
fn players(&self) -> Option<&dyn Players> { ... }
fn media_assets(&self) -> Option<&dyn MediaAssets> { ... }
fn image_codecs(&self) -> Option<&dyn ImageCodecs> { ... }
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§
Sourcefn target_platform(&self) -> TargetPlatform
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.
Sourcefn request_frame(&self, view: ViewId)
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.
Sourcefn dispatcher(&self) -> Arc<dyn Dispatcher> ⓘ
fn dispatcher(&self) -> Arc<dyn Dispatcher> ⓘ
The host’s threads, for waking the application or running work off the main thread: see
Dispatcher.
Provided Methods§
Sourcefn request_view(
&self,
config: WindowConfig,
initial_data: Option<String>,
) -> Result<RequestId, ViewError>
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, Android a task of its own, an iPad that has more than one window
of the app’s a window scene; a platform that gives the app its views and makes none, an
iPhone 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.
Sourcefn locales(&self) -> Vec<Locale>
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.
Sourcefn set_application_locale(&self, locale: &Locale)
fn set_application_locale(&self, locale: &Locale)
Tells the host which locale the application resolved to (Flutter
PlatformDispatcher.setApplicationLocale); the default drops it.
Sourcefn time_zone_offset(&self, seconds_since_epoch: i64) -> SignedDuration
fn time_zone_offset(&self, seconds_since_epoch: i64) -> SignedDuration
The local time zone’s offset from UTC at seconds_since_epoch, positive east of UTC: the
Dart VM’s DateTime_timeZoneOffsetInSeconds, which DateTime asks for each local value
it makes. The instant is already within the years a 32-bit time_t holds, as the VM maps
it (DateTime’s equivalent year). The host asks the system on every call, keeping
nothing, so a change of zone shows in the next value made. The default is UTC’s zero, for
a host with no zone to ask.
Sourcefn time_zone_name(&self, seconds_since_epoch: i64) -> String
fn time_zone_name(&self, seconds_since_epoch: i64) -> String
The local time zone’s name at seconds_since_epoch, as the system gives it (an
abbreviation such as “CET” on a C library and in a browser, the full name on Windows):
the Dart VM’s DateTime_timeZoneName, asked as time_zone_offset
is. The default is “UTC”.
Sourcefn briefly_show_password(&self) -> bool
fn briefly_show_password(&self) -> bool
Whether briefly displaying the characters as you type in obscured text fields is enabled
in system settings (Flutter PlatformDispatcher.brieflyShowPassword).
Defaults to true, dart:ui’s value until a host reports the setting. dart:ui has no
callback for its change: a host answers the setting as it is now, and the framework reads
it as it needs it, as EditableText does at each tick of its cursor.
Sourcefn platform_brightness(&self) -> Brightness
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.
Sourcefn default_route_name(&self) -> String
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.
Sourcefn initial_lifecycle_state(&self) -> Option<AppLifecycleState>
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.
Sourcefn font_source(&self) -> Option<Box<dyn FontSource>>
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.
Sourcefn default_font_families(&self) -> Vec<String>
fn default_font_families(&self) -> Vec<String>
Flutter’s txt::GetDefaultFontFamilies(): the families text uses when its style names
none, first match first.
The engine decides this per OS, so the host answers it: one on an OS Flutter names gives
that OS’s default_font_families, and one whose fonts are
not the OS’s, as a web page’s are not, answers its own. Defaults to txt/platform.cc, the
engine’s answer on an OS it has no file of its own for.
Sourcefn open_image_codec(&self, bytes: Arc<[u8]>) -> ImageCodecFuture
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.
Sourcefn import_pixels(&self, pixels: PixelBuffer) -> Option<Image>
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.
Sourcefn picture_to_image_sync(
&self,
picture: &Picture,
width: u32,
height: u32,
) -> Option<Image>
fn picture_to_image_sync( &self, picture: &Picture, width: u32, height: u32, ) -> Option<Image>
Synchronously creates a handle to an image of picture: Flutter’s Picture.toImageSync.
The returned image will be width pixels wide and height pixels high. The picture is
rasterized within the 0 (left), 0 (top), width (right), height (bottom) bounds.
Content outside these bounds is clipped. The image lives on the renderer’s device, and
anything drawn with it waits for it there.
It is a call on the platform, where Dart’s is on the picture, because only the host
holds a device to draw on. None when the host has no renderer to draw it with.
§Panics
Where width or height is zero: “Invalid image dimensions.”.
Sourcefn read_image_pixels(&self, image: &Image) -> ImageFuture<PixelBuffer>
fn read_image_pixels(&self, image: &Image) -> ImageFuture<PixelBuffer>
image’s pixels read back from the device it lives on, as straight-alpha RGBA: Dart’s
Image.toByteData(format: ImageByteFormat.rawStraightRgba), as a test reads what a widget
paints. It is a call on the platform, where Dart’s is on the image, because only the host
holds the device; a host answers it through its SnapshotDelegate.
ImageErrorKind::Unsupported where the
host has no renderer.
Sourcefn import_video_frame(&self, frame: &dyn VideoFrame) -> Option<Image>
fn import_video_frame(&self, frame: &dyn VideoFrame) -> Option<Image>
An image of a video frame the app holds, its hardware buffer imported as a texture on the
renderer’s device with no copy (import_texture), holding the frame
while the image lives: a still picture a media asset read, drawn as any image. Not
Flutter’s: its Texture widget draws a source’s frames as they come, as VideoFrameView
does. None when the host has no renderer to put it on yet, or the renderer’s device cannot
take the frame’s memory.
Sourcefn import_hardware_buffer(&self, buffer: &dyn HardwareBuffer) -> Option<Image>
fn import_hardware_buffer(&self, buffer: &dyn HardwareBuffer) -> Option<Image>
An image of a hardware buffer the app holds, imported as a texture on the renderer’s device
with no copy (import_texture), holding the buffer while the image
lives: an image the hardware codecs decoded, or a buffer the app drew, drawn as any image.
None when the host has no renderer to put it on yet, or the renderer’s device cannot take
the buffer’s memory.
Sourcefn import_texture(
&self,
buffer: &dyn HardwareBuffer,
device: &Device,
) -> Option<Texture>
fn import_texture( &self, buffer: &dyn HardwareBuffer, device: &Device, ) -> Option<Texture>
buffer, one this host handed out and of one plane, imported as a texture on device over
its memory with no copy, as the system’s GPU API imports such memory (Metal’s texture over
an IOSurface, Vulkan’s external memory over an AHardwareBuffer): of the buffer’s size, for what its
usage names, sampled where the GPU samples it, drawn into and copied into where it draws
into it, and copied from whatever its usage. The texture holds the buffer, and a video
frame’s buffer its frame, until the GPU is done with it. The host imports it, as the one
that knows both the buffer and the device; a buffer names no GPU API. None for a buffer
another host handed out, for a buffer of two planes, which
import_planes imports, and for a device that cannot take the
buffer’s memory: on Apple platforms a wgpu device not on Metal. Not dart:ui’s: Flutter’s engine keeps its textures to
itself.
Sourcefn import_planes(
&self,
buffer: &dyn HardwareBuffer,
device: &Device,
) -> Option<Vec<TextureView>>
fn import_planes( &self, buffer: &dyn HardwareBuffer, device: &Device, ) -> Option<Vec<TextureView>>
buffer, one this host handed out, imported on device with no copy as one texture view
per plane, brightness first, each in the format
HardwareBufferFormat::plane_format names and
of the size plane_size names: what a shader
samples to convert a decoder’s picture to colour with the frame’s
VideoFrame::color. The views are of one texture per plane on
Metal, which has no texture of two planes, and the plane aspects of one NV12 or P010
texture on D3D12. A buffer of one plane is one view of its texture, as
import_texture makes it. Each view holds its texture, and the
texture the buffer, and a frame’s buffer its frame, until the GPU is done with it. None
for a buffer another host handed out, for a device that cannot take its memory or sample
its planes’ formats, and on a host that imports no planes.
Sourcefn gpu_id(&self, device: &Device) -> Option<GpuId>
fn gpu_id(&self, device: &Device) -> Option<GpuId>
The GPU device runs on, as its system names it: what an app that draws with device
asks for its decoders and allocator with, platform.gpu(platform.gpu_id(&device)), so
their memory opens on that device. None where the system names no GPU (Apple’s systems,
Android), and for a device whose backend says nothing of its GPU (OpenGL, a Vulkan driver
without VK_EXT_physical_device_drm). Only the host reads it, as the one that knows which
backend the device is on.
Sourcefn gpu(&self, id: Option<GpuId>) -> Option<Rc<dyn SystemGpu>>
fn gpu(&self, id: Option<GpuId>) -> Option<Rc<dyn SystemGpu>>
The GPU id names, or the system’s default where None, with what the system makes for
it: its video decoders and its hardware buffer allocator. None where the system has no
such GPU, and where it hands out nothing for any. Apple’s systems and Android have one,
whatever id names, as their memory opens on any of the machine’s GPUs.
Sourcefn compositor(&self) -> Option<Arc<dyn Compositor>>
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.
Sourcefn vsync_waiter(&self) -> Option<Arc<dyn VsyncWaiter>>
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.
Sourcefn screens(&self) -> Option<&dyn Screens>
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.
Sourcefn clipboard(&self) -> Option<&dyn Clipboard>
fn clipboard(&self) -> Option<&dyn Clipboard>
The system clipboard, or None where the host has none.
Sourcefn system_chrome(&self) -> Option<&dyn SystemChrome>
fn system_chrome(&self) -> Option<&dyn SystemChrome>
The system UI drawn around the app, or None where the host has none.
Sourcefn haptics(&self) -> Option<&dyn Haptics>
fn haptics(&self) -> Option<&dyn Haptics>
Haptic feedback on the device, or None where the host has none.
The system’s own menu over a text selection, or None where the host has none.
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).
Menus the system opens at a point in a view, or None where the system has none and the
framework draws them.
Sourcefn tray_icons(&self) -> Option<&dyn TrayIcons>
fn tray_icons(&self) -> Option<&dyn TrayIcons>
The app’s icons in the system’s tray, or None where the system has no tray.
Sourcefn file_dialogs(&self) -> Option<&dyn FileDialogs>
fn file_dialogs(&self) -> Option<&dyn FileDialogs>
The system’s file dialogs, or None where the system has none.
Sourcefn http(&self) -> Option<&dyn HttpClient>
fn http(&self) -> Option<&dyn HttpClient>
The system’s HTTP client, or None where the host has none. A client sends every method,
streams bodies both ways, follows redirects as the request asks, and cancels a transfer
dropped mid-way; NetworkImage fetches through it, and an app may as well. A host that
carries the system’s session honours its proxy and its certificates.
Sourcefn files(&self) -> Option<&dyn Files>
fn files(&self) -> Option<&dyn Files>
The system’s file system, or None where the host has none, as a browser tab has none.
Every path an app reads or writes goes through it, a picked file’s among them
(PickedFile::read_all); FileImage reads through it.
Sourcefn players(&self) -> Option<&dyn Players>
fn players(&self) -> Option<&dyn Players>
The system’s media players, or None where the host has none.
Sourcefn media_assets(&self) -> Option<&dyn MediaAssets>
fn media_assets(&self) -> Option<&dyn MediaAssets>
The system’s reading of media without playing it, or None where the host has none.
Sourcefn image_codecs(&self) -> Option<&dyn ImageCodecs>
fn image_codecs(&self) -> Option<&dyn ImageCodecs>
The system’s image codecs, or None where the host has none.
Sourcefn cameras(&self) -> Option<&dyn Cameras>
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.
Sourcefn video_frame_readers(&self) -> Option<&dyn VideoFrameReaders>
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.
Sourcefn caption_settings(&self) -> Option<&dyn CaptionSettings>
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.
Sourcefn view_embedder(&self) -> Option<&dyn ViewEmbedder>
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.
The menu of the app’s Dock icon, or None where the system has no Dock.
Sourcefn text_services(&self) -> Option<&dyn TextServices>
fn text_services(&self) -> Option<&dyn TextServices>
The system services a selection toolbar offers, or None where the host has none.
Sourcefn restoration(&self) -> Option<&dyn Restoration>
fn restoration(&self) -> Option<&dyn Restoration>
Application state kept across relaunches, or None where the host has none.
Sourcefn app_exit(&self) -> Option<&dyn AppExit>
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.
Sourcefn opener(&self) -> Option<&dyn Opener>
fn opener(&self) -> Option<&dyn Opener>
The system’s way to open links and files in other apps, or None where it has none.
Sourcefn notifications(&self) -> Option<&dyn Notifications>
fn notifications(&self) -> Option<&dyn Notifications>
The system’s notifications, or None where it has none for the app.
Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".