在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):material-foundation/google-fonts-flutter开源软件地址(OpenSource Url):https://github.com/material-foundation/google-fonts-flutter开源编程语言(OpenSource Language):Dart 99.3%开源软件介绍(OpenSource Introduction):google_fontsA Flutter package to use fonts from fonts.google.com. Features
Getting StartedFor example, say you want to use the Lato font from Google Fonts in your Flutter app. First, add the To import import 'package:google_fonts/google_fonts.dart'; To use 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 Text(
'This is Google Fonts',
style: GoogleFonts.lato(
textStyle: TextStyle(color: Colors.blue, letterSpacing: .5),
),
), or Text(
'This is Google Fonts',
style: GoogleFonts.lato(textStyle: Theme.of(context).textTheme.headline4),
), To override the Text(
'This is Google Fonts',
style: GoogleFonts.lato(
textStyle: Theme.of(context).textTheme.headline4,
fontSize: 48,
fontWeight: FontWeight.w700,
fontStyle: FontStyle.italic,
),
), You can also use ...
return MaterialApp(
theme: _buildTheme(Brightness.dark),
);
}
ThemeData _buildTheme(brightness) {
var baseTheme = ThemeData(brightness: brightness);
return baseTheme.copyWith(
textTheme: GoogleFonts.latoTextTheme(baseTheme.textTheme),
);
} Or, if you want a final textTheme = Theme.of(context).textTheme;
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.latoTextTheme(textTheme).copyWith(
body1: GoogleFonts.oswald(textStyle: textTheme.body1),
),
),
); HTTP fetchingFor 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:
Learn more at https://docs.flutter.dev/development/data-and-backend/networking#platform-notes. Font bundling in assetsThe
{
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',
}
Note: Since these files are listed as assets, there is no need to list them in the See the API docs to completely disable HTTP fetching. Licensing FontsThe fonts on fonts.google.com include license files for each font. For
example, the Lato font comes with an 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 license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
runApp(...);
} TestingSee example/test for testing examples. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论