diff --git a/packages/google_fonts/CHANGELOG.md b/packages/google_fonts/CHANGELOG.md index 4367327638ef..c6ee16e8898a 100644 --- a/packages/google_fonts/CHANGELOG.md +++ b/packages/google_fonts/CHANGELOG.md @@ -1,5 +1,10 @@ +## 7.0.2 + +- Adds missing public API documentation + ## 7.0.1 -- Exclude variable font entries when a static entry of the same weight and style exists + +- Excludes variable font entries when a static entry of the same weight and style exists ## 7.0.0 diff --git a/packages/google_fonts/lib/src/google_fonts_base.dart b/packages/google_fonts/lib/src/google_fonts_base.dart index c8e956b5fabc..6486f8f51972 100755 --- a/packages/google_fonts/lib/src/google_fonts_base.dart +++ b/packages/google_fonts/lib/src/google_fonts_base.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(stuartmorgan): Revisit the use of print for reporting errors. -// ignore_for_file: avoid_print - import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -184,22 +181,22 @@ Future loadFontIfNecessary(GoogleFontsDescriptor descriptor) async { } } catch (e) { _loadedFonts.remove(familyWithVariantString); - print( + debugPrint( 'Error: google_fonts was unable to load font $fontName because the ' 'following exception occurred:\n$e', ); if (file_io.isTest) { - print( + debugPrint( '\nThere is likely something wrong with your test. Please see ' 'https://github.com/flutter/packages/blob/main/packages/google_fonts/example/test ' 'for examples of how to test with google_fonts.', ); } else if (file_io.isMacOS || file_io.isAndroid) { - print( + debugPrint( '\nSee https://docs.flutter.dev/development/data-and-backend/networking#platform-notes.', ); } - print( + debugPrint( "If troubleshooting doesn't solve the problem, please file an issue " 'at https://github.com/flutter/flutter/issues/new/choose.\n', ); diff --git a/packages/google_fonts/lib/src/google_fonts_descriptor.dart b/packages/google_fonts/lib/src/google_fonts_descriptor.dart index 93a17b64bfe9..126ef9f756fd 100644 --- a/packages/google_fonts/lib/src/google_fonts_descriptor.dart +++ b/packages/google_fonts/lib/src/google_fonts_descriptor.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(stuartmorgan): Remove, and fix violations. -// ignore_for_file: public_member_api_docs - import 'google_fonts_family_with_variant.dart'; /// Describes a Google Fonts API font. @@ -12,12 +9,22 @@ import 'google_fonts_family_with_variant.dart'; /// This class mostly serves as a simple way to keep the connected font /// information together. class GoogleFontsDescriptor { + /// Creates a descriptor for a Google Fonts font. + /// + /// The [familyWithVariant] describes the font family and variant, while + /// the [file] contains information about the font file such as its hash and + /// expected length. const GoogleFontsDescriptor({ required this.familyWithVariant, required this.file, }); + /// The font family and variant information. + /// + /// Example: "Roboto" with a variant with weight "400" and style "regular". final GoogleFontsFamilyWithVariant familyWithVariant; + + /// The font file information including hash and expected length. final GoogleFontsFile file; } @@ -27,10 +34,18 @@ class GoogleFontsDescriptor { /// is not of [expectedLength] bytes length, the font will not be loaded, and /// the file will not be stored on the device. class GoogleFontsFile { + /// Creates a font file descriptor with expected hash and length validation. + /// + /// The [expectedFileHash] is used to verify the integrity of the downloaded + /// file, and [expectedLength] is checked to ensure the file size is correct. GoogleFontsFile(this.expectedFileHash, this.expectedLength); + /// The expected hash of the font file for validation. final String expectedFileHash; + + /// The expected length in bytes of the font file. final int expectedLength; + /// The URL from which the font file can be downloaded. String get url => 'https://fonts.gstatic.com/s/a/$expectedFileHash.ttf'; } diff --git a/packages/google_fonts/lib/src/google_fonts_family_with_variant.dart b/packages/google_fonts/lib/src/google_fonts_family_with_variant.dart index d04c0fc24ba0..949e9cb61fcf 100644 --- a/packages/google_fonts/lib/src/google_fonts_family_with_variant.dart +++ b/packages/google_fonts/lib/src/google_fonts_family_with_variant.dart @@ -2,21 +2,27 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(stuartmorgan): Remove, and fix violations. -// ignore_for_file: public_member_api_docs - import 'google_fonts_variant.dart'; /// Represents a Google Fonts API variant in Flutter-specific types. class GoogleFontsFamilyWithVariant { + /// Creates a representation of a Google Fonts family with a specific variant. const GoogleFontsFamilyWithVariant({ required this.family, required this.googleFontsVariant, }); + /// The name of the Google Fonts family. + /// + /// Example: "Roboto", "Open Sans", etc. final String family; + + /// The variant information including weight and style. final GoogleFontsVariant googleFontsVariant; + /// Returns the API filename prefix for this font family and variant. + /// + /// Example: "Roboto-400" for regular Roboto. String toApiFilenamePrefix() { return '$family-${googleFontsVariant.toApiFilenamePart()}'; } diff --git a/packages/google_fonts/lib/src/google_fonts_variant.dart b/packages/google_fonts/lib/src/google_fonts_variant.dart index 878831ddfdce..d1ed5f0350a2 100644 --- a/packages/google_fonts/lib/src/google_fonts_variant.dart +++ b/packages/google_fonts/lib/src/google_fonts_variant.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(stuartmorgan): Remove, and fix violations. -// ignore_for_file: public_member_api_docs - import 'dart:ui'; import 'package:flutter/foundation.dart' show immutable; @@ -12,6 +9,7 @@ import 'package:flutter/foundation.dart' show immutable; /// Represents a Google Fonts API variant in Flutter-specific types. @immutable class GoogleFontsVariant { + /// Creates a [GoogleFontsVariant] with a specific font weight and style. const GoogleFontsVariant({required this.fontWeight, required this.fontStyle}); /// Creates a [GoogleFontsVariant] from a Google Fonts API specific @@ -52,7 +50,14 @@ class GoogleFontsVariant { ? FontStyle.italic : FontStyle.normal; + /// The font weight of this variant. + /// + /// Example: [FontWeight.w400] for regular weight, [FontWeight.w700] for bold. final FontWeight fontWeight; + + /// The font style of this variant. + /// + /// Example: [FontStyle.normal] for regular, [FontStyle.italic] for italic. final FontStyle fontStyle; static FontWeight _extractFontWeightFromApiFilenamePart(String filenamePart) { diff --git a/packages/google_fonts/pubspec.yaml b/packages/google_fonts/pubspec.yaml index d2aec347e413..1e445e3712a5 100644 --- a/packages/google_fonts/pubspec.yaml +++ b/packages/google_fonts/pubspec.yaml @@ -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: 7.0.1 +version: 7.0.2 environment: sdk: ^3.9.0