Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/google_fonts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.2.0

- Extract the class `Config` to its own file and rename it `GoogleFontsConfig`. The `Config` name will be deprecated in a future release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is deprecated though in this change, isn't it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Extract the class `Config` to its own file and rename it `GoogleFontsConfig`. The `Config` name will be deprecated in a future release.
- Extract the class `Config` to its own file and rename it `GoogleFontsConfig`. The `Config` class is now deprecated.


## 8.1.0

- Adds the ability to supply a custom HTTP client to `GoogleFonts.config`.
Expand Down
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
1 change: 1 addition & 0 deletions packages/google_fonts/lib/google_fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// found in the LICENSE file.

export 'src/google_fonts_all_parts.dart';
export 'src/google_fonts_config.dart';
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
23 changes: 23 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,23 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:http/http.dart' as http;
Comment thread
TheCarpetMerchant marked this conversation as resolved.

/// 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 +9 to +20

Copy link
Copy Markdown
Contributor

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are good points. We should try to avoid a breaking change unless absolutely necessary, and in order to allow users to access this class, it should be exported.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This just clutters the namespace for nothing, especially with such a common name as "Config".
The only purpose of the class was to be a clear separation between configuration fields and the rest of the GoogleFonts class, there is no utility to developers having their own instance for other purposes (again, especially with this unfortunate "Config" name). As a dev I would rather not have this in my namespace and I see removing it as an improvement.

Still, if you'd rather not have a breaking change I'll export the google_fonts_config file. It really does seem like a negative to me though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation! I agree that Config is a very generic name and renaming it to GoogleFontsConfig is a solid improvement to avoid cluttering the namespace.

However, we still need to export GoogleFontsConfig because otherwise, developers cannot reference the type directly (e.g., they won't be able to write GoogleFontsConfig cfg = GoogleFonts.config; or pass it to configuration helper functions).

Since we recently bumped the major version, using a deprecation path is best to avoid churn on the ecosystem. We can expose a deprecated typedef in google_fonts_config.dart and export it in lib/google_fonts.dart. We can then clean up and remove this deprecation in a future major version bump.

@Deprecated('Use GoogleFontsConfig instead')
typedef Config = GoogleFontsConfig;

What do you think about using this deprecation path?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


@Deprecated('Use GoogleFontsConfig instead')
typedef Config = GoogleFontsConfig;
Comment on lines +22 to +23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will still need a public doc comment on it to pass analysis:

/// Deprecated. Use [GoogleFontsConfig] instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This documentation is still needed.

2 changes: 1 addition & 1 deletion packages/google_fonts/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_fonts
description: A Flutter package to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.
repository: https://github.com/flutter/packages/tree/main/packages/google_fonts
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
version: 8.1.0
version: 8.2.0

environment:
sdk: ^3.9.0
Expand Down