Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerize all fonts #571

Open
YukiAttano opened this issue Mar 24, 2024 · 0 comments
Open

Enumerize all fonts #571

YukiAttano opened this issue Mar 24, 2024 · 0 comments
Labels
enhancement New feature or request p: google_fonts

Comments

@YukiAttano
Copy link

Package

google_fonts

Description

Is your feature request related to a problem? Please describe.
I would like to access all fonts in a simple list like "GoogleFonts.fonts".
Therefor the only function to achieve something like this is "GoogleFonts.asMap()" which returns all fonts as String/Builder Function pair.

Describe the solution you'd like
Wouldn't it be easier for the whole library to put all fonts in enumes?
like

 typedef TextStyleBuilder = TextStyle Function({
  TextStyle? textStyle,
  Color? color,
  Color? backgroundColor,
  double? fontSize,
  FontWeight? fontWeight,
  FontStyle? fontStyle,
  double? letterSpacing,
  double? wordSpacing,
  TextBaseline? textBaseline,
  double? height,
  Locale? locale,
  Paint? foreground,
  Paint? background,
  List<ui.Shadow>? shadows,
  List<ui.FontFeature>? fontFeatures,
  TextDecoration? decoration,
  Color? decorationColor,
  TextDecorationStyle? decorationStyle,
  double? decorationThickness,
});


enum GoogleFont {
  ABeeZee,
  ADLaM_Display;
  // ...

  final String name;
  final TextStyleBuilder builder;
}

This way, one could easily retrieve a list of all fonts, could check if a given font is valid and pass the font typesafe around instead of holding a String.

Describe alternatives you've considered
Possibly another "improvement" (excuse me that i don't open another issue for that) would be to reduce the "static TextTheme almaraiTextTheme([TextTheme? textTheme])" TextThemeBuilder functions that are probably auto generated, with a simple callback like:

// Example almari function:
  static TextTheme almaraiTextTheme([TextTheme? textTheme]) {
    textTheme ??= ThemeData.light().textTheme;
    return TextTheme(
      displayLarge: almarai(textStyle: textTheme.displayLarge),
      displayMedium: almarai(textStyle: textTheme.displayMedium),
      displaySmall: almarai(textStyle: textTheme.displaySmall),
      headlineLarge: almarai(textStyle: textTheme.headlineLarge),
      headlineMedium: almarai(textStyle: textTheme.headlineMedium),
      headlineSmall: almarai(textStyle: textTheme.headlineSmall),
      titleLarge: almarai(textStyle: textTheme.titleLarge),
      titleMedium: almarai(textStyle: textTheme.titleMedium),
      titleSmall: almarai(textStyle: textTheme.titleSmall),
      bodyLarge: almarai(textStyle: textTheme.bodyLarge),
      bodyMedium: almarai(textStyle: textTheme.bodyMedium),
      bodySmall: almarai(textStyle: textTheme.bodySmall),
      labelLarge: almarai(textStyle: textTheme.labelLarge),
      labelMedium: almarai(textStyle: textTheme.labelMedium),
      labelSmall: almarai(textStyle: textTheme.labelSmall),
    );
  }

// to:
 static TextTheme almaraiTextTheme([TextTheme? textTheme]) {
    textTheme ??= ThemeData.light().textTheme;
    return googleFontTextTheme(GoogleFont.almari);
 }

static TextTheme googleFontTextTheme(TextStyleBuilder builder, [TextTheme? textTheme]) {
  textTheme ??= ThemeData.light().textTheme;

  return TextTheme(
      displayLarge: builder(textStyle: textTheme.displayLarge),
      displayMedium: builder(textStyle: textTheme.displayMedium),
      displaySmall: builder(textStyle: textTheme.displaySmall),
      headlineLarge: builder(textStyle: textTheme.headlineLarge),
      headlineMedium: builder(textStyle: textTheme.headlineMedium),
      headlineSmall: builder(textStyle: textTheme.headlineSmall),
      titleLarge: builder(textStyle: textTheme.titleLarge),
      titleMedium: builder(textStyle: textTheme.titleMedium),
      titleSmall: builder(textStyle: textTheme.titleSmall),
      bodyLarge: builder(textStyle: textTheme.bodyLarge),
      bodyMedium: builder(textStyle: textTheme.bodyMedium),
      bodySmall: builder(textStyle: textTheme.bodySmall),
      labelLarge: builder(textStyle: textTheme.labelLarge),
      labelMedium: builder(textStyle: textTheme.labelMedium),
      labelSmall: builder(textStyle: textTheme.labelSmall),
    );
 }

Additional context
I am interested if this is an option and why it is currently made the way it is, which looks like a lot of boilerplate for every single GoogleFont for me.

@YukiAttano YukiAttano added enhancement New feature or request triage Issues that haven't been triaged labels Mar 24, 2024
@guidezpl guidezpl added p: google_fonts and removed triage Issues that haven't been triaged labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p: google_fonts
Projects
None yet
Development

No branches or pull requests

2 participants