dart 字体未改变(抖动)

lokaqttq  于 2023-02-06  发布在  其他
关注(0)|答案(3)|浏览(134)

这是密码:

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: SafeArea(
            child: Center(
          child: Container(
            child: const Text(
              'you talk of the pain like it is all alright',
              style: TextStyle(
                fontFamily: 'Arima',
                fontSize: 20.0,
              ),
            ),
          ),
        )),
      ),
    ),
  );
}

这是出版说明书

# To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Arima
      fonts:
        - asset: fonts/Arima-Regular.ttf
  #      - asset: fonts/Arima-Italic.ttf

  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

我正在学习flutter,我不知道为什么字体不改变,即使我做的一切,我在YouTube上看了很多视频,但它没有工作,即使我做了视频中的一切

fykwrbwg

fykwrbwg1#

这里有几件事需要检查!

注:像添加字体/资源到pubspec.yaml这样的更改只有在热重新加载/重新启动后才适用,并且需要您完全重新启动flutter。

A:文件在位置不存在

确保字体文件确实存在于fonts/Arima-Regular.ttf中。根目录是您的项目目录(包含libpubspec.yaml等的文件夹)。

B:字体文件无效

请确认字体文件是有效的!你可以在FontDrop这样的网站上检查。

C:Pubspec.yaml无效

运行flutter pub get并确保pubspec.yaml文件有效。

D:仅网络

检查此答案以获得解决方案!

E:生成缓存需要清理

运行flutter clean并重新启动应用程序。

flvlnr44

flvlnr442#

我有问题,因为错误的缩进字体部分的pubspec文件。注意空格或所要求的使用字体将被忽略,没有任何错误或警告的Flutter。

uxhixvfz

uxhixvfz3#

格式问题。请检查:

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/
    - assets/demo/
    - translations/
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Rubik
      fonts:
        - asset: assets/fonts/Rubik-Regular.ttf
          weight: 300
        - asset: assets/fonts/Rubik-Black.ttf
          weight: 400
        - asset: assets/fonts/Rubik-Bold.ttf
          weight: 700
        - asset: assets/fonts/Rubik-Medium.ttf
          weight: 500
        - asset: assets/fonts/Rubik-SemiBold.ttf
          weight: 600

  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

相关问题