### Main Application Widget Source: https://pub.dev/packages/google_fonts/example This is the main entry point for the google_fonts demo application. It sets up the basic Material App structure with tabs for different examples. ```dart // 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. // ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; import 'example_font_selection.dart'; import 'example_simple.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData.light(useMaterial3: true), home: DefaultTabController( animationDuration: Duration.zero, length: 2, child: Scaffold( appBar: AppBar( title: const Text('Google Fonts Demo'), bottom: const TabBar( tabs: [ Tab(text: 'Simple'), Tab(text: 'Select a font'), ], ), ), body: const TabBarView( children: [ExampleSimple(), ExampleFontSelection()], ), ), ), ); } } ``` -------------------------------- ### Pubspec.yaml Dependency Entry Source: https://pub.dev/packages/google_fonts/install This is an example of how the google_fonts dependency will appear in your pubspec.yaml file after running the add command. It also implies an automatic `flutter pub get`. ```yaml dependencies: google_fonts: ^8.1.0 ``` -------------------------------- ### Registering Font Licenses Source: https://pub.dev/packages/google_fonts Add font licenses to your Flutter application's LicenseRegistry. This example shows how to load a license file from assets and register it. ```dart void main() { LicenseRegistry.addLicense(() async* { final String license = await rootBundle.loadString('google_fonts/OFL.txt'); yield LicenseEntryWithLineBreaks(['google_fonts'], license); }); runApp(const MyApp()); } ``` -------------------------------- ### Import google_fonts in Dart Source: https://pub.dev/packages/google_fonts/install Import the google_fonts package into your Dart files to start using its functionalities for integrating Google Fonts. ```dart import 'package:google_fonts/google_fonts.dart'; ``` -------------------------------- ### macOS Network Entitlement for HTTP Fetching Source: https://pub.dev/packages/google_fonts Configure macOS entitlements to allow network access for HTTP fetching of Google Fonts. This is a platform-specific requirement for debug and release builds. ```xml com.apple.security.network.client ``` -------------------------------- ### Dynamically Load Google Font Source: https://pub.dev/packages/google_fonts Load a Google Font dynamically by its name. This is useful when the font name might be determined at runtime. ```dart Text('This is Google Fonts', style: GoogleFonts.getFont('Lato')), ``` -------------------------------- ### Font Weight to Filename Mapping Source: https://pub.dev/packages/google_fonts This map shows the correspondence between FontWeight enum values and the expected filename suffixes for Google Fonts. Ensure your downloaded font files match these naming conventions. ```dart { 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', }; ``` -------------------------------- ### Apply Google Font to Existing TextStyle Source: https://pub.dev/packages/google_fonts Integrate a Google Font with an existing TextStyle, allowing you to combine custom styles with the chosen font. This is useful for applying specific font properties like color or letter spacing. ```dart Text( 'This is Google Fonts', style: GoogleFonts.lato( textStyle: const TextStyle(color: Colors.blue, letterSpacing: .5), ), ), ``` -------------------------------- ### Apply Google Font to Theme TextStyle Source: https://pub.dev/packages/google_fonts Use a Google Font with a TextStyle derived from the current theme. This allows for consistent font application across different text styles defined in your app's theme. ```dart Text( 'This is Google Fonts', style: GoogleFonts.lato( textStyle: Theme.of(context).textTheme.headlineMedium, ), ), ``` -------------------------------- ### Apply Google Font to Entire Text Theme Source: https://pub.dev/packages/google_fonts Modify an entire TextTheme to use a specific Google Font. This is ideal for establishing a consistent typographic hierarchy throughout your application. ```dart class MyApp extends StatelessWidget { // ··· @override Widget build(BuildContext context) { return MaterialApp( // ··· theme: _buildTheme(Brightness.dark), // ··· ); } } ThemeData _buildTheme(Brightness brightness) { final baseTheme = ThemeData(brightness: brightness); return baseTheme.copyWith( textTheme: GoogleFonts.latoTextTheme(baseTheme.textTheme), ); } ``` -------------------------------- ### Add google_fonts Dependency Source: https://pub.dev/packages/google_fonts/install Use this command to add the google_fonts package to your Flutter project's dependencies. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add google_fonts ``` -------------------------------- ### Modify Text Theme with Different Fonts Source: https://pub.dev/packages/google_fonts Customize a TextTheme by applying different Google Fonts to specific text styles. This allows for a varied typographic design within your app. ```dart final TextTheme textTheme = Theme.of(context).textTheme; return MaterialApp( // ··· theme: ThemeData( textTheme: GoogleFonts.latoTextTheme(textTheme).copyWith( bodyMedium: GoogleFonts.oswald(textStyle: textTheme.bodyMedium), ), ), // ··· ); ``` -------------------------------- ### Use Google Font in Text Widget Source: https://pub.dev/packages/google_fonts Apply a Google Font directly to a Text widget using its font family name. This is the most straightforward way to use a specific font. ```dart Text('This is Google Fonts', style: GoogleFonts.lato()), ``` -------------------------------- ### Override TextStyle Properties with Google Font Source: https://pub.dev/packages/google_fonts Apply a Google Font and override specific TextStyle properties like fontSize, fontWeight, or fontStyle. This provides fine-grained control over the appearance of text elements. ```dart Text( 'This is Google Fonts', style: GoogleFonts.lato( textStyle: Theme.of(context).textTheme.displayLarge, fontSize: 48, fontWeight: FontWeight.w700, fontStyle: FontStyle.italic, ), ), ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.