当前位置:网站首页>[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
2022-07-02 22:17:00 【Programmer community】
List of articles
- One 、Flutter Custom Fonts
- 1、ttf The font file
- 2、ttf Font resource configuration
- 3、 Get the font
- 4、 Use fonts globally
- 5、 Use fonts locally
- Two 、 Complete code example
- 3、 ... and 、 Related resources
One 、Flutter Custom Fonts
1、ttf The font file
Font resource file : ttf Format font resources ;
Flutter Apply font resource file : stay Flutter Create... In the application root directory fonts Catalog , Will download ttf The font is placed in the resource file fonts Under the table of contents ;
2、ttf Font resource configuration
Configure font resources : Custom font resources need to be in pubspec.yaml Configuration in profile , The font resource configuration format is as follows :
fonts: - family: Schyler fonts: - asset: fonts/Schyler-Regular.ttf - asset: fonts/Schyler-Italic.ttf style: italic - family: Trajan Pro fonts: - asset: fonts/TrajanPro.ttf - asset: fonts/TrajanPro_Bold.ttf weight: 700
Use here RubikMonoOne-Regular.ttf The font file , The configuration is as follows :
flutter: # Configure image resources assets: - images/hunter.png # Configure font resources fonts: - family: RubikMonoOne fonts: - asset: fonts/RubikMonoOne-Regular.ttf
The font file corresponding to this configuration RubikMonoOne-Regular.ttf Put it in the root directory fonts Under the table of contents ;
3、 Get the font
stay pubspec.yaml After configuring font resources in the configuration file , Click on " Pub get " Button , Synchronize resources ;
After displaying the following , It indicates that the resource synchronization is successful ;
D:\001_Programs\004_Flutter\flutter\bin\flutter.bat --no-color pub getRunning "flutter pub get" in flutter_cmd... 0.7sProcess finished with exit code 0
4、 Use fonts globally
Apply fonts globally : stay MaterialApp The root node of the theme Field value ThemeData In the component fontFamily Field setting font , It's set here pubspec.yaml Configuration file family The value under the tag “RubikMonoOne” ;
Font configuration :
fonts: - family: RubikMonoOne fonts: - asset: fonts/RubikMonoOne-Regular.ttf
Code example :
MaterialApp( // Set title title: , // Set the theme theme: ThemeData( // Configure Fonts fontFamily: "RubikMonoOne" ), // Set the main components of the interface home: ,)
5、 Use fonts locally
Apply fonts locally : stay Text Of style Field set text style , TextStyle Of type components fontFamily You can set the font ;
Code example :
Text( "StatefulWidget Page lifecycle ", style: TextStyle( fontFamily: "RubikMonoOne" ),),
Two 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';import 'package:flutter_cmd/GesturePage.dart';import 'package:flutter_cmd/ResourcePage.dart';import 'package:flutter_cmd/StatelessWidgetPage.dart';import 'package:flutter_cmd/WidgetLifeCyclePage.dart';import 'AppLiftCyclePage.dart';import 'LauncherPage.dart';import 'LayoutPage.dart';import 'StatefulWidgetPage.dart';import 'ThemePage.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {
@override Widget build(BuildContext context) {
return MaterialApp( // Set title title: 'Flutter Demo', // Set the theme theme: ThemeData( // Configure Fonts fontFamily: "RubikMonoOne", // Configure theme colors primarySwatch: Colors.blue, ), // Set the main components of the interface home: Scaffold( // Set the title bar appBar: AppBar( title: Text(" Routing and navigation "), ), // Set the main components of the interface body: RouteNavigator(), ), // Configure the routing routes: <String, WidgetBuilder>{
"StatelessWidgetPage" : (BuildContext context) => StatelessWidgetPage(), "StatefulWidgetPage" : (BuildContext context) => StatefulWidgetPage(), "LayoutPage" : (BuildContext context) => LayoutPage() }, ); }}class RouteNavigator extends StatefulWidget {
@override _RouteNavigatorState createState() => _RouteNavigatorState();}class _RouteNavigatorState extends State<RouteNavigator> {
@override Widget build(BuildContext context) {
return Container( // In the middle alignment: Alignment.center, child: Column( children: <Widget>[ RaisedButton( onPressed: (){
Navigator.pushNamed(context, "LayoutPage"); }, child: Text(" Jump to the page by route name 1"), ), RaisedButton( onPressed: (){
Navigator.pushNamed(context, "StatefulWidgetPage"); }, child: Text(" Jump to the page by route name 2"), ), RaisedButton( onPressed: (){
Navigator.pushNamed(context, "StatelessWidgetPage"); }, child: Text(" Jump to the page by route name 3"), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => LayoutPage())); }, child: Text(" Navigate to the page 1"), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => StatefulWidgetPage())); }, child: Text(" Navigate to the page 2"), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => StatelessWidgetPage())); }, child: Text(" Navigate to the page 3"), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => GesturePage())); }, child: Text(" Gesture detection interface "), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => ResourcePage())); }, child: Text(" Resource usage interface "), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => LauncherPage())); }, child: Text(" Third party application jump "), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => WidgetLiftCyclePage())); }, child: Text("StatefulWidget Page lifecycle ", style: TextStyle(fontFamily: "RubikMonoOne"),), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => AppLifeCyclePage())); }, child: Text(" Application life cycle "), ), RaisedButton( onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => ThemePage())); }, child: Text(" Topic switching "), ), ], ), ); }}
Operation effect display :
3、 ... and 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Plug in download address : https://pub.dev/packages
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net ( unofficial , The translation is very good ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_cmd ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/15602328 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Basic IO interface technology - microcomputer Chapter 7 Notes
- Structure array, pointer and function and application cases
- 发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
- How do I access the kubernetes API?
- What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
- Pyqt picture decodes and encodes and loads pictures
- "Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
- 20220702-程序员如何构建知识体系?
- Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
- 【C 题集】of Ⅴ
猜你喜欢
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
Etcd raft protocol
The difference between include < > and include ""
How do I access the kubernetes API?
#include<>和#include“”的区别
*C语言期末课程设计*——通讯录管理系统(完整项目+源代码+详细注释)
[shutter] shutter layout component (physicalmodel component)
About test cases
MySQL learning record (5)
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
随机推荐
B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
分享一下如何制作专业的手绘电子地图
From personal heroes to versatile developers, the era of programmer 3.0 is coming
Etcd raft protocol
Web侧防御指南
Learn computer knowledge from scratch
#include<>和#include“”的区别
Destroy in beforedestroy invalid value in localstorage
MySQL learning record (5)
Service visibility and observability
关于测试用例
Redis distributed lock failure, I can't help but want to burst
Daily book CSO advanced road first exposed
tinymce可视化编辑器增加百度地图插件
How to test the process of restoring backup files?
Detailed explanation of OSI seven layer model
地理探测器原理介绍
Three chess games
Off chip ADC commissioning record