Skip to content

Commit d31e955

Browse files
authored
[google_fonts] Add missing public API documentation (#10782)
Also replace `print` with `debugPrint`
1 parent eb9e1dc commit d31e955

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

packages/google_fonts/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
## 7.0.2
2+
3+
- Adds missing public API documentation
4+
15
## 7.0.1
2-
- Exclude variable font entries when a static entry of the same weight and style exists
6+
7+
- Excludes variable font entries when a static entry of the same weight and style exists
38

49
## 7.0.0
510

packages/google_fonts/lib/src/google_fonts_base.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// TODO(stuartmorgan): Revisit the use of print for reporting errors.
6-
// ignore_for_file: avoid_print
7-
85
import 'package:crypto/crypto.dart';
96
import 'package:flutter/material.dart';
107
import 'package:flutter/services.dart';
@@ -184,22 +181,22 @@ Future<void> loadFontIfNecessary(GoogleFontsDescriptor descriptor) async {
184181
}
185182
} catch (e) {
186183
_loadedFonts.remove(familyWithVariantString);
187-
print(
184+
debugPrint(
188185
'Error: google_fonts was unable to load font $fontName because the '
189186
'following exception occurred:\n$e',
190187
);
191188
if (file_io.isTest) {
192-
print(
189+
debugPrint(
193190
'\nThere is likely something wrong with your test. Please see '
194191
'https://github.com/flutter/packages/blob/main/packages/google_fonts/example/test '
195192
'for examples of how to test with google_fonts.',
196193
);
197194
} else if (file_io.isMacOS || file_io.isAndroid) {
198-
print(
195+
debugPrint(
199196
'\nSee https://docs.flutter.dev/development/data-and-backend/networking#platform-notes.',
200197
);
201198
}
202-
print(
199+
debugPrint(
203200
"If troubleshooting doesn't solve the problem, please file an issue "
204201
'at https://github.com/flutter/flutter/issues/new/choose.\n',
205202
);

packages/google_fonts/lib/src/google_fonts_descriptor.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// TODO(stuartmorgan): Remove, and fix violations.
6-
// ignore_for_file: public_member_api_docs
7-
85
import 'google_fonts_family_with_variant.dart';
96

107
/// Describes a Google Fonts API font.
118
///
129
/// This class mostly serves as a simple way to keep the connected font
1310
/// information together.
1411
class GoogleFontsDescriptor {
12+
/// Creates a descriptor for a Google Fonts font.
13+
///
14+
/// The [familyWithVariant] describes the font family and variant, while
15+
/// the [file] contains information about the font file such as its hash and
16+
/// expected length.
1517
const GoogleFontsDescriptor({
1618
required this.familyWithVariant,
1719
required this.file,
1820
});
1921

22+
/// The font family and variant information.
23+
///
24+
/// Example: "Roboto" with a variant with weight "400" and style "regular".
2025
final GoogleFontsFamilyWithVariant familyWithVariant;
26+
27+
/// The font file information including hash and expected length.
2128
final GoogleFontsFile file;
2229
}
2330

@@ -27,10 +34,18 @@ class GoogleFontsDescriptor {
2734
/// is not of [expectedLength] bytes length, the font will not be loaded, and
2835
/// the file will not be stored on the device.
2936
class GoogleFontsFile {
37+
/// Creates a font file descriptor with expected hash and length validation.
38+
///
39+
/// The [expectedFileHash] is used to verify the integrity of the downloaded
40+
/// file, and [expectedLength] is checked to ensure the file size is correct.
3041
GoogleFontsFile(this.expectedFileHash, this.expectedLength);
3142

43+
/// The expected hash of the font file for validation.
3244
final String expectedFileHash;
45+
46+
/// The expected length in bytes of the font file.
3347
final int expectedLength;
3448

49+
/// The URL from which the font file can be downloaded.
3550
String get url => 'https://fonts.gstatic.com/s/a/$expectedFileHash.ttf';
3651
}

packages/google_fonts/lib/src/google_fonts_family_with_variant.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// TODO(stuartmorgan): Remove, and fix violations.
6-
// ignore_for_file: public_member_api_docs
7-
85
import 'google_fonts_variant.dart';
96

107
/// Represents a Google Fonts API variant in Flutter-specific types.
118
class GoogleFontsFamilyWithVariant {
9+
/// Creates a representation of a Google Fonts family with a specific variant.
1210
const GoogleFontsFamilyWithVariant({
1311
required this.family,
1412
required this.googleFontsVariant,
1513
});
1614

15+
/// The name of the Google Fonts family.
16+
///
17+
/// Example: "Roboto", "Open Sans", etc.
1718
final String family;
19+
20+
/// The variant information including weight and style.
1821
final GoogleFontsVariant googleFontsVariant;
1922

23+
/// Returns the API filename prefix for this font family and variant.
24+
///
25+
/// Example: "Roboto-400" for regular Roboto.
2026
String toApiFilenamePrefix() {
2127
return '$family-${googleFontsVariant.toApiFilenamePart()}';
2228
}

packages/google_fonts/lib/src/google_fonts_variant.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// TODO(stuartmorgan): Remove, and fix violations.
6-
// ignore_for_file: public_member_api_docs
7-
85
import 'dart:ui';
96

107
import 'package:flutter/foundation.dart' show immutable;
118

129
/// Represents a Google Fonts API variant in Flutter-specific types.
1310
@immutable
1411
class GoogleFontsVariant {
12+
/// Creates a [GoogleFontsVariant] with a specific font weight and style.
1513
const GoogleFontsVariant({required this.fontWeight, required this.fontStyle});
1614

1715
/// Creates a [GoogleFontsVariant] from a Google Fonts API specific
@@ -52,7 +50,14 @@ class GoogleFontsVariant {
5250
? FontStyle.italic
5351
: FontStyle.normal;
5452

53+
/// The font weight of this variant.
54+
///
55+
/// Example: [FontWeight.w400] for regular weight, [FontWeight.w700] for bold.
5556
final FontWeight fontWeight;
57+
58+
/// The font style of this variant.
59+
///
60+
/// Example: [FontStyle.normal] for regular, [FontStyle.italic] for italic.
5661
final FontStyle fontStyle;
5762

5863
static FontWeight _extractFontWeightFromApiFilenamePart(String filenamePart) {

packages/google_fonts/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_fonts
22
description: A Flutter package to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_fonts
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
5-
version: 7.0.1
5+
version: 7.0.2
66

77
environment:
88
sdk: ^3.9.0

0 commit comments

Comments
 (0)