FontFaceObserver class

A FontFaceObserver is responsible for loading and detecting when a font has been successfully loaded into the browser and is ready for use in the DOM or drawn into a canvas. If you need to load fonts with an authenticated request, you can handle the networking part yourself and then still use FontFaceObserver to detect when it is ready by passing in the font as a base64 data or Blob URI.

Constructors

FontFaceObserver(String family, {String style = _normal, String weight = _normal, String stretch = _normal, String testString = _defaultTestString, int timeout = _defaultTimeout, @Deprecated('This option does nothing now that simulated font load event support is removed') dynamic useSimulatedLoadEvents = false, String group = defaultGroup})
Construct a new FontFaceObserver. The CSS font family name is the only required parameter.

Properties

family String
CSS font family
getter/setter pair
group String
Returns the group that this FontFaceObserver is in
no setter
hashCode int
The hash code for this object.
no setterinherited
key String
Returns the key for this FontFaceObserver
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stretch String
CSS font stretch
getter/setter pair
style String
CSS font style
getter/setter pair
testString String
Returns the test string used to detect this font load
getter/setter pair
timeout int
How long to wait in ms when detecting font loads before timing out
getter/setter pair
useSimulatedLoadEvents bool
This option is always false now that simulated font load event support is removed
final
weight String
CSS font weight
getter/setter pair

Methods

check() Future<FontLoadResult>
Wait for the font face represented by this FontFaceObserver to become available in the browser. It will asynchronously return a FontLoadResult with the result of whether or not the font is loaded or the timeout was reached while waiting for it to become available.
load(String url) Future<FontLoadResult>
Load the font into the browser given a url that could be a network url or a pre-built data or blob url.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

getLoadedFontKeys() Iterable<String>
Returns the font keys for all currently loaded fonts
getLoadedGroups() Iterable<String>
Returns the groups that the currently loaded fonts are in. There will not be duplicate group entries if there are multiple fonts in the same group.
unload(String key, String group) Future<bool>
Unloads a font by passing in the key and group that was used to load it originally. It will decremement the use count for a matching font and if no one else is using it, then it will be removed from the browser by removing the style element and removing the internal tracking of the font.
unloadGroup(String group) Future<int>
Sets the use count for the given group to zero for any fonts in that group, then unloads any fonts that are not used any more. A font will only be actually unloaded from the browser once its use count is zero. So, if the same font is used by multiple different groups it will have a count of uses per group and will need to be unloaded from each group to truly unload it from the browser.

Constants

defaultGroup → const String
The default group used for a font if none is specified.