ae203771创建于 2025年11月13日历史提交
文件最后提交记录最后更新时间
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
[all] add pubspec issue_tracker & screenshots 3 年前
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
Updates to conform to flutter/packages - Update repo metadata - Update pubspec.yaml to follow repo conventions - Remove cider dependency - Remove git-ignored files - Use a suffix for generated files - Switch to repo analysis options and fix violations - Standardize licenses - Update links and docs to match changes - Reformat CHANGELOG - Update links - Adopt readme excerpts - Update min Flutter SDK version - Autoformat - Switch font download links to https - Update Android exmaple/ Gradle files - Delete example/unit_test.dart - Annotate test files that are not web-compatible - Bump minimum plugin_platform_interface version to satisfy downgrade analysis 8 个月前
Updates to conform to flutter/packages - Update repo metadata - Update pubspec.yaml to follow repo conventions - Remove cider dependency - Remove git-ignored files - Use a suffix for generated files - Switch to repo analysis options and fix violations - Standardize licenses - Update links and docs to match changes - Reformat CHANGELOG - Update links - Adopt readme excerpts - Update min Flutter SDK version - Autoformat - Switch font download links to https - Update Android exmaple/ Gradle files - Delete example/unit_test.dart - Annotate test files that are not web-compatible - Bump minimum plugin_platform_interface version to satisfy downgrade analysis 8 个月前
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
[google_fonts] Improve CONTRIBUTING and generator README (#9917) Apply feedback from https://github.com/flutter/packages/pull/9895 Note: the families_diff file created by the generator should suffice in writing CHANGELOG updates ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.8 个月前
Remove "All right reserved" from all files (#10066) Per guidance from legal on current preferred practice, remove "All rights reserved" from all LICENSE files and header blocks, and update the repo tool check accordingly.7 个月前
Updates to conform to flutter/packages - Update repo metadata - Update pubspec.yaml to follow repo conventions - Remove cider dependency - Remove git-ignored files - Use a suffix for generated files - Switch to repo analysis options and fix violations - Standardize licenses - Update links and docs to match changes - Reformat CHANGELOG - Update links - Adopt readme excerpts - Update min Flutter SDK version - Autoformat - Switch font download links to https - Update Android exmaple/ Gradle files - Delete example/unit_test.dart - Annotate test files that are not web-compatible - Bump minimum plugin_platform_interface version to satisfy downgrade analysis 8 个月前
Update repo for 3.38 (#10405) Does all of the steps from https://github.com/flutter/flutter/blob/master/docs/ecosystem/release/Updating-Packages-repo-for-a-stable-release.md for the 3.38 release (except the first one, which the stable roller will handle). This includes a lot of autoformat changes, because the N-2 is now 3.32, which means many packages are now being updated to a min Dart SDK of 3.8, triggering a formatter behavior change.6 个月前
README.md

google_fonts

pub package

A Flutter package to use fonts from fonts.google.com.

changing fonts with google_fonts and hot reload

Features

video thumbnail

  • HTTP fetching at runtime, ideal for development. Can also be used in production to reduce app size
  • Font file caching, on device file system
  • Font bundling in assets. Matching font files found in assets are prioritized over HTTP fetching. Useful for offline-first apps.

Usage

For example, say you want to use the Lato font from Google Fonts in your Flutter app.

  1. Add the google_fonts package to your pubspec dependencies.

Text styles

To use GoogleFonts with the default TextStyle:

Text('This is Google Fonts', style: GoogleFonts.lato()),

Or, if you want to load the font dynamically:

Text('This is Google Fonts', style: GoogleFonts.getFont('Lato')),

To use GoogleFonts with an existing TextStyle:

Text(
  'This is Google Fonts',
  style: GoogleFonts.lato(
    textStyle: const TextStyle(color: Colors.blue, letterSpacing: .5),
  ),
),

or

Text(
  'This is Google Fonts',
  style: GoogleFonts.lato(
    textStyle: Theme.of(context).textTheme.headlineMedium,
  ),
),

To override the fontSize, fontWeight, or fontStyle:

Text(
  'This is Google Fonts',
  style: GoogleFonts.lato(
    textStyle: Theme.of(context).textTheme.displayLarge,
    fontSize: 48,
    fontWeight: FontWeight.w700,
    fontStyle: FontStyle.italic,
  ),
),

Text themes

You can also use GoogleFonts.latoTextTheme() to make or modify an entire text theme to use the "Lato" font.

class MyApp extends StatelessWidget {
  // ···
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // ···
      theme: _buildTheme(Brightness.dark),
      // ···
    );
  }
}

ThemeData _buildTheme(Brightness brightness) {
  final ThemeData baseTheme = ThemeData(brightness: brightness);

  return baseTheme.copyWith(
    textTheme: GoogleFonts.latoTextTheme(baseTheme.textTheme),
  );
}

Or, if you want a TextTheme where a couple of styles should use a different font:

final TextTheme textTheme = Theme.of(context).textTheme;

return MaterialApp(
  // ···
  theme: ThemeData(
    textTheme: GoogleFonts.latoTextTheme(textTheme).copyWith(
      bodyMedium: GoogleFonts.oswald(textStyle: textTheme.bodyMedium),
    ),
  ),
  // ···
);

Visual font swapping

To avoid visual font swaps that occur when a font is loading, use FutureBuilder and GoogleFonts.pendingFonts().

See the example app.

HTTP fetching

For HTTP fetching to work, certain platforms require additional steps when running the app in debug and/or release mode. For example, macOS requires the following be present in the relevant .entitlements file:

<key>com.apple.security.network.client</key>
<true/>

Learn more at https://docs.flutter.dev/development/data-and-backend/networking#platform-notes.

Bundling fonts when releasing

The google_fonts package will automatically use matching font files in your pubspec.yaml's assets (rather than fetching them at runtime via HTTP). Once you've settled on the fonts you want to use:

  1. Download the font files from https://fonts.google.com. You only need to download the weights and styles you are using for any given family. Italic styles will include Italic in the filename. Font weights map to file names as follows:
<FontWeight, String>{
  FontWeight.w100: 'Thin',
  FontWeight.w200: 'ExtraLight',
  FontWeight.w300: 'Light',
  FontWeight.w400: 'Regular',
  FontWeight.w500: 'Medium',
  FontWeight.w600: 'SemiBold',
  FontWeight.w700: 'Bold',
  FontWeight.w800: 'ExtraBold',
  FontWeight.w900: 'Black',
};
  1. Move those fonts to some asset folder (e.g. google_fonts). You can name this folder whatever you like and use subdirectories.

  1. Ensure that you have listed the asset folder (e.g. google_fonts/) in your pubspec.yaml, under assets.

Note: Since these files are listed as assets, there is no need to list them in the fonts section of the pubspec.yaml. This can be done because the files are consistently named from the Google Fonts API (so be sure not to rename them!)

See the API docs to completely disable HTTP fetching.

Licensing Fonts

The fonts on fonts.google.com include license files for each font. For example, the Lato font comes with an OFL.txt file.

Once you've decided on the fonts you want in your published app, you should add the appropriate licenses to your flutter app's LicenseRegistry.

For example:

void main() {
  LicenseRegistry.addLicense(() async* {
    final String license = await rootBundle.loadString('google_fonts/OFL.txt');
    yield LicenseEntryWithLineBreaks(<String>['google_fonts'], license);
  });

  runApp(const MyApp());
}

Testing

See example/test for testing examples.