Flutter使用思源字體


1、找到字體ttf

https://github.com/Pal3love/Source-Han-TrueType

2、導入項目

  fonts:
- family: NotoSerif
  fonts:
  - asset: assets/fonts/NotoSerif-Regular.ttf
  - asset: assets/fonts/SourceHanSansCN-Light.ttf

3、使用

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {

  // declare the text style
  const textStyle = const TextStyle(
    fontFamily: 'NotoSerif',
  );

// use the text style
  var buttonText = const Text(
    "思源宋體",
    style: textStyle,
  );

  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: _incrementCounter,
          child: buttonText,
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM