FontRegistry class


FontRegistry

Centralized registry for managing multiple font families in a Flutter design system package.

Purpose:

  • Allows any host project to "register" one or more font families by key.
  • Ensures that FontHelper can access the correct font at runtime without hardcoding font names in the package.
  • Fully reusable in multi-brand, multi-client, or white-label applications.

Features:

  • Supports registering multiple fonts using FontKey (predefined or custom).
  • Throws a descriptive exception if a requested font key is not registered, preventing silent fallback to the system font.
  • Works seamlessly with FontHelper, AppTextStyles, and other typography helpers to provide consistent, scalable, theme-driven text styling.

Usage:

// Register fonts once at app startup
FontRegistry.instance.registerFont(FontKey.primary, 'Inter');
FontRegistry.instance.registerFont(FontKey.secondary, 'Roboto');
FontRegistry.instance.registerFont(FontKey.custom('brandX'), 'CustomFont');

// Retrieve a font in FontHelper or any typography helper
final primaryFont = FontRegistry.instance.getFont(FontKey.primary);
final secondaryFont = FontRegistry.instance.getFont(FontKey.secondary);
final brandXFont = FontRegistry.instance.getFont(FontKey.custom('brandX'));

Notes:

  • Designed for packages or libraries where font names cannot be hardcoded.
  • Enables consistent typography across all screens and widgets.
  • Works with scaling, line height, and font weight abstractions when used with FontHelper.

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 Methods

getFont(FontKey key) String
Retrieve a font family by FontKey
registerFont(FontKey key, String fontFamily) → void
Register a font family with a FontKey