Skip to content

feat: Add customTextTheme parameter to flutterNesTheme() for non-Latin locale support #246

Description

@kyungilcho

Description

Currently, flutterNesTheme() hardcodes the Press Start 2P font via GoogleFonts.pressStart2pTextTheme(). This works great for Latin-character projects, but makes it difficult to use nes_ui in projects that need non-Latin scripts (Korean, Japanese, Chinese, etc.).

Google Fonts does not offer pixel fonts for CJK languages, so bundling custom fonts (e.g. Galmuri for Korean) is the only option for non-Latin NES-style projects.

Current Workaround

The only workaround is to override textTheme via .copyWith() after calling flutterNesTheme():

theme: flutterNesTheme(...).copyWith(
  textTheme: ThemeData.light().textTheme.apply(fontFamily: 'Galmuri11'),
),

However, this has a subtle issue: internal theme calculations in flutterNesTheme() (e.g. NesContainerTheme.labelTextStyle, NesProgressBarTheme.background, NesTooltipTheme.background) are already computed using the Press Start 2P textTheme before the .copyWith() override is applied.

Proposed Solution

Add an optional TextTheme? customTextTheme parameter to flutterNesTheme():

ThemeData flutterNesTheme({
  TextTheme? customTextTheme,
  // ... existing params
}) {
  final textTheme = customTextTheme 
      ?? GoogleFonts.pressStart2pTextTheme(themeData.textTheme);
  // ...
}

Usage Example

MaterialApp(
  theme: flutterNesTheme(
    customTextTheme: ThemeData.light().textTheme.apply(
      fontFamily: 'Galmuri11',
    ),
  ),
)

This is a non-breaking, backward-compatible change. When customTextTheme is not provided, the behavior is identical to the current implementation.

I am happy to submit a PR for this if the approach looks good!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions