Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions packages/google_fonts/generator/google_fonts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,13 @@
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import 'google_fonts_base.dart';
import 'google_fonts_config.dart';
{{#allParts}}
import '{{partFilePath}}';
{{/allParts}}

/// A collection of properties used to specify custom behavior of the
/// GoogleFonts library.
class Config {
/// Whether or not the GoogleFonts library can make requests to
/// [fonts.google.com](https://fonts.google.com/) to retrieve font files.
bool allowRuntimeFetching = true;

/// The HTTP client used to fetch fonts.
///
/// If this is null, a shared default [http.Client] will be used.
///
/// If you supply a client, you are responsible for closing it.
http.Client? httpClient;
}

/// Provides configuration, and static methods to obtain [TextStyle]s and [TextTheme]s.
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=8Vzv2CdbEY0}
Expand All @@ -49,7 +34,7 @@ class GoogleFonts {
/// ```dart
/// GoogleFonts.config.allowRuntimeFetching = false;
/// ```
static final Config config = Config();
static final GoogleFontsConfig config = GoogleFontsConfig();

/// Returns a [Future] which resolves when requested fonts have finished
/// loading and are ready to be rendered on screen.
Expand Down
19 changes: 2 additions & 17 deletions packages/google_fonts/lib/src/google_fonts_all_parts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import 'google_fonts_base.dart';
import 'google_fonts_config.dart';
import 'google_fonts_parts/part_a.dart';
import 'google_fonts_parts/part_b.dart';
import 'google_fonts_parts/part_c.dart';
Expand Down Expand Up @@ -39,21 +39,6 @@ import 'google_fonts_parts/part_x.dart';
import 'google_fonts_parts/part_y.dart';
import 'google_fonts_parts/part_z.dart';

/// A collection of properties used to specify custom behavior of the
/// GoogleFonts library.
class Config {
/// Whether or not the GoogleFonts library can make requests to
/// [fonts.google.com](https://fonts.google.com/) to retrieve font files.
bool allowRuntimeFetching = true;

/// The HTTP client used to fetch fonts.
///
/// If this is null, a shared default [http.Client] will be used.
///
/// If you supply a client, you are responsible for closing it.
http.Client? httpClient;
}

/// Provides configuration, and static methods to obtain [TextStyle]s and [TextTheme]s.
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=8Vzv2CdbEY0}
Expand All @@ -72,7 +57,7 @@ class GoogleFonts {
/// ```dart
/// GoogleFonts.config.allowRuntimeFetching = false;
/// ```
static final Config config = Config();
static final GoogleFontsConfig config = GoogleFontsConfig();

/// Returns a [Future] which resolves when requested fonts have finished
/// loading and are ready to be rendered on screen.
Expand Down
16 changes: 16 additions & 0 deletions packages/google_fonts/lib/src/google_fonts_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:http/http.dart' as http;

/// A collection of properties used to specify custom behavior of the
/// GoogleFonts library.
class GoogleFontsConfig {
/// Whether or not the GoogleFonts library can make requests to
/// [fonts.google.com](https://fonts.google.com/) to retrieve font files.
bool allowRuntimeFetching = true;

/// The HTTP client used to fetch fonts.
///
/// If this is null, a shared default [http.Client] will be used.
///
/// If you supply a client, you are responsible for closing it.
http.Client? httpClient;
}
Comment on lines +5 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Renaming the Config class to GoogleFontsConfig is a breaking change for any users who have explicitly typed the GoogleFonts.config object in their code.

To maintain backward compatibility while adopting the more specific name, consider adding a deprecated typedef for Config. Additionally, ensure that GoogleFontsConfig (and the typedef) is exported from the package's public API (e.g., lib/google_fonts.dart), as GoogleFonts.config is a public field and its type should be accessible to consumers.

Suggested change
class GoogleFontsConfig {
/// Whether or not the GoogleFonts library can make requests to
/// [fonts.google.com](https://fonts.google.com/) to retrieve font files.
bool allowRuntimeFetching = true;
/// The HTTP client used to fetch fonts.
///
/// If this is null, a shared default [http.Client] will be used.
///
/// If you supply a client, you are responsible for closing it.
http.Client? httpClient;
}
class GoogleFontsConfig {
/// Whether or not the GoogleFonts library can make requests to
/// [fonts.google.com](https://fonts.google.com/) to retrieve font files.
bool allowRuntimeFetching = true;
/// The HTTP client used to fetch fonts.
///
/// If this is null, a shared default [http.Client] will be used.
///
/// If you supply a client, you are responsible for closing it.
http.Client? httpClient;
}
/// Deprecated. Use [GoogleFontsConfig] instead.
@Deprecated('Use GoogleFontsConfig instead')
typedef Config = GoogleFontsConfig;