Skip to content

Commit

Permalink
[Google Fonts] Update Font method from fooTextStyle() to foo()
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonmh committed Dec 10, 2019
1 parent f425e3a commit bd44fcd
Show file tree
Hide file tree
Showing 7 changed files with 13,544 additions and 13,456 deletions.
99 changes: 97 additions & 2 deletions README.md
@@ -1,2 +1,97 @@
# google-fonts-flutter
A Flutter package for accessing the Google Fonts API
# google_fonts

NOTE: This package is in Beta. The API is subject to change.

The `google_fonts` package for Flutter allows you to easily use any of the 960 fonts
(and their variants) from [fonts.google.com](fonts.google.com) in your Flutter app.

## Getting Started

![](https://raw.githubusercontent.com/material-components/material-components-flutter-experimental/master/google_fonts/main.gif)

With the `google_fonts` package, `.ttf` files do not need to be stored in your assets folder and mapped in
the pubspec. Instead, they are fetched once via http at runtime, and cached in the app's file system. This is ideal for development, and can be the preferred behavior for production apps that
are looking to reduce the app bundle size.

For example, say you want to use the [Lato](https://fonts.google.com/specimen/Lato) font from Google Fonts in your Flutter app.

First, add the `google_fonts` package to your [pubspec dependencies](https://pub.dev/packages/google_fonts#-installing-tab-).

To import `GoogleFonts`:

```dart
import 'package:google_fonts/google_fonts.dart';
```

To use `GoogleFonts` with the default TextStyle:

```dart
Text(
'This is Google Fonts',
style: GoogleFonts.latoTextStyle(),
),
```

To use `GoogleFonts` with an existing `TextStyle`:

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

or

```dart
Text(
'This is Google Fonts',
style: GoogleFonts.latoTextStyle(textStyle: Theme.of(context).textTheme.display1),
),
```

To override the `fontSize`, `fontWeight`, or `fontStyle`:

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

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

```dart
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.latoTextTheme(
Theme.of(context).textTheme,
),
),
);
```

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

```dart
final textTheme = Theme.of(context).textTheme;
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.latoTextTheme(textTheme).copyWith(
body1: GoogleFonts.oswaldTextStyle(textStyle: textTheme.body1),
),
),
);
```

## What's Next?

In a future release, this package will defer to `.ttf` files you specify in the pubspec before fetching them via http. This means you can get the best of both worlds by having access to all [fonts.google.com](fonts.google.com) fonts and their variants during development, while also ensuring your production app has an optimal offline/slow connection experience.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Expand Up @@ -47,11 +47,11 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
Text(
'You have pushed the button this many times:',
style: GoogleFonts.oswaldTextStyle(textStyle: display1),
style: GoogleFonts.oswald(textStyle: display1),
),
Text(
'$_counter',
style: GoogleFonts.latoTextStyle(fontStyle: FontStyle.italic),
style: GoogleFonts.lato(fontStyle: FontStyle.italic),
),
],
),
Expand Down
9 changes: 1 addition & 8 deletions example/pubspec.lock
Expand Up @@ -80,7 +80,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.8"
version: "0.1.0"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -116,13 +116,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
mustache:
dependency: transitive
description:
name: mustache
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
path:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions generator/google_fonts.tmpl
Expand Up @@ -12,7 +12,7 @@ import 'src/google_fonts_variant.dart';

class GoogleFonts {
{{#method}}
static TextStyle {{methodName}}TextStyle({
static TextStyle {{methodName}}({
TextStyle textStyle,
double fontSize,
FontWeight fontWeight,
Expand All @@ -38,7 +38,7 @@ class GoogleFonts {
textTheme ??= ThemeData.light().textTheme;
return TextTheme(
{{#themeParams}}
{{value}}: GoogleFonts.{{methodName}}TextStyle(textStyle: textTheme?.{{value}}),
{{value}}: GoogleFonts.{{methodName}}(textStyle: textTheme?.{{value}}),
{{/themeParams}}
);
}
Expand Down

0 comments on commit bd44fcd

Please sign in to comment.