Skip to content
Merged
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
7 changes: 6 additions & 1 deletion packages/google_fonts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 4 additions & 7 deletions packages/google_fonts/lib/src/google_fonts_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -184,22 +181,22 @@ Future<void> 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',
);
Expand Down
21 changes: 18 additions & 3 deletions packages/google_fonts/lib/src/google_fonts_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
// 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.
///
/// 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;
}

Expand All @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()}';
}
Expand Down
11 changes: 8 additions & 3 deletions packages/google_fonts/lib/src/google_fonts_variant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// 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;

/// 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
Expand Down Expand Up @@ -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) {
Expand Down
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: 7.0.1
version: 7.0.2

environment:
sdk: ^3.9.0
Expand Down
Loading