VirtualKeypadColorEmoji class
Registers a color emoji font at runtime, so web can show color emoji without every app paying for one in its bundle.
The bundled fallback is monochrome because a color emoji font is large: subset to the same codepoints, Noto Color Emoji in COLRv1 form is roughly 3.9 MB against 708 KB, because COLRv1 draws each emoji from many single-color layer glyphs. Shipping that to every app, including the mobile ones that already get color emoji from the system font, is a poor trade.
Loading it at runtime avoids the trade entirely. The keyboard renders the bundled monochrome font immediately, and swaps to color if and when the font arrives. If the fetch fails, because the device is offline or the request was blocked, the monochrome font simply stays. Emoji always render.
Opt in by passing VirtualKeypad.colorEmojiFontLoader:
VirtualKeypad(
standalone: true,
enableEmojiKey: true,
colorEmojiFontLoader: () async {
final response = await http.get(Uri.parse(myColorEmojiFontUrl));
return ByteData.sublistView(response.bodyBytes);
},
)
Self-host the font rather than hot-linking someone else's CDN. Kiosk, ATM, and enterprise deployments often disallow outbound requests, which is why this is opt in and why the package never fetches anything on its own.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
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 Properties
-
isLoaded
→ ValueNotifier<
bool> -
Whether the color font has been registered.
final
Static Methods
-
load(
EmojiFontBytesLoader loader) → Future< bool> - Loads and registers the color emoji font, at most once per app.
-
resetForTesting(
) → void - Clears the memoized load so a test can exercise it again.
Constants
- fontFamily → const String
- Family the runtime-loaded color emoji font is registered under.