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);
}

Leave a Reply

邮箱地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>