Flutter 应用中的 Google 字体包不起作用

Tof*_*ali 5 fonts package flutter

首先,我将 google_fonts 包添加到您的 pubspec 依赖项中。

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  google_fonts: ^0.2.0
Run Code Online (Sandbox Code Playgroud)

然后

import 'package:google_fonts/google_fonts.dart';
Run Code Online (Sandbox Code Playgroud)

并应用于文本小部件

        Text(
          'This is Google Fonts',
          style: GoogleFonts.lato(fontSize: 40),
        ),
        Text(
          'This is Google Fonts',
          style: GoogleFonts.adventPro(fontSize: 40),
        ),
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

dha*_*kar 8

请检查互联网连接 - 您的模拟器没有互联网连接。谷歌字体需要设备/模拟器上的互联网连接。