當前位置:
首頁 >
在 Flutter 中更改文本的字体系列
發布時間:2025/3/19
27
豆豆
生活随笔
收集整理的這篇文章主要介紹了
在 Flutter 中更改文本的字体系列
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在 Flutter 中更改文本的字體系列
將字體 .ttf 文件添加到應用程序的文件夾中。說。assets/font/
將資產和字體添加到 pubspec.yaml 文件中的 flutter 屬性。您可以向應用程序添加一種或多種字體系列。在本教程中,我們將添加兩種字體。
flutter:uses-material-design: trueassets:- assets/font/fonts:- family: Font1fonts:- asset: assets/font/font1.ttf- family: Font2fonts:- asset: assets/font/font2.ttfmain.dart
import 'package:flutter/material.dart';void main() {runApp(MaterialApp(home: MyApp(),)); }class MyApp extends StatefulWidget {@override_MyAppState createState() => _MyAppState(); }class _MyAppState extends State<MyApp> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: new Text("Flutter Tutorial - googleflutter.com"),),body: Center(child: Column(children: <Widget>[Container(padding: EdgeInsets.all(20),child: Text('Welcome to Flutter Tutorial by googleflutter.com',style: TextStyle(fontFamily: "Font1", fontSize: 40, fontWeight: FontWeight.bold),),),Container(padding: EdgeInsets.all(20),child: Text('Welcome to Flutter Tutorial by googleflutter.com',style: TextStyle(fontFamily: "Font2",fontSize: 40,fontWeight: FontWeight.bold),)),])),);} }截圖
https://googleflutter.com/flutter-text-change-font-family/
本文由博客一文多發平臺 OpenWrite 發布!
總結
以上是生活随笔為你收集整理的在 Flutter 中更改文本的字体系列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flutter面试常见开发问题
- 下一篇: android - FlutterAct