字体下的意外关键资产((字符串)) - 颤动和飞镖中的移动应用程序错误
Posted
技术标签:
【中文标题】字体下的意外关键资产((字符串)) - 颤动和飞镖中的移动应用程序错误【英文标题】:Unexpected key assets ((String)) under font - Mobile app error in flutter and dart 【发布时间】:2019-09-20 19:03:03 【问题描述】:我是移动开发的新手,我正在使用 Dart 和 Flutter 构建移动应用程序,包括 android 和 ios 应用程序。问题是我无法启动我的应用程序,并且不断收到与 pubspec.yaml
文件相关的错误。
当我评论fonts:
部分时,应用程序运行正常。但是我需要加载字体,所以这并不能解决我的问题。
这是我的pubspec.yaml
name: simple_app
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: Oxygen
fonts:
- assets: assets/fonts/Oxygen-Regular.ttf
- assets: assets/fonts/Oxygen-Light.ttf
- assets: assets/fonts/Oxygen-Bold.ttf
assets:
- assets/images/
下面是我在控制台中不断遇到的错误。
Error detected in pubspec.yaml:
Unexpected key assets ((String)) under font.
Unexpected key assets ((String)) under font.
Unexpected key assets ((String)) under font.
C:\Users\user\Documents\mobile_app\flutter\simple_app\pubspec.yaml
exit code 1
【问题讨论】:
资产,而不是资产。请查看flutter.dev/docs/cookbook/design/fonts omg 非常感谢@AlekseyPotapov,这也是我的问题,它让我疯狂地试图弄清楚我做错了什么 【参考方案1】:字体: - 家庭:Poppins 字体: - 资产:资产/字体/Poppins-Black.ttf
检查资产和资产之间是否存在差异。请检查并更新它。
【讨论】:
【参考方案2】:请看我的工作示例
fonts:
- family: icomoon
fonts:
- asset: assets/fonts/IcoMoon.ttf
- family: Qwigley
fonts:
- asset: assets/fonts/Qwigley-Regular.ttf
- family: Dosis
fonts:
- asset: assets/fonts/dosis/Dosis-Regular.otf
weight: 400
- asset: assets/fonts/dosis/Dosis-Medium.otf
weight: 500
- asset: assets/fonts/dosis/Dosis-SemiBold.otf
weight: 600
- asset: assets/fonts/dosis/Dosis-Bold.otf
weight: 800
- asset: assets/fonts/dosis/Dosis-ExtraBold.otf
weight: 900
【讨论】:
【参考方案3】:试试这个pubspec.yaml
:
name: custom_fonts
description: An example of how to use custom fonts with Flutter
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
fonts:
- family: DUBAI
fonts:
- asset: assets/fonts/DUBAI-BOLD.TTF
- asset: assets/fonts/DUBAI-LIGHT.TTF
- asset: assets/fonts/DUBAI-MEDIUM.TTF
- asset: assets/fonts/DUBAI-REGULAR.TTF
- family: Dima
fonts:
- asset: assets/fonts/DimaPlatinum.ttf
uses-material-design: true
assets:
- assets/azmoon.db
- assets/qi1.png
也许你想看看main.dart
:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Custom Fonts',
// Set Raleway as the default app font.
theme: ThemeData(fontFamily: 'Raleway'),
home: MyHomePage(),
);
class MyHomePage extends StatelessWidget
@override
Widget build(BuildContext context)
return Scaffold(
// The AppBar uses the app-default Raleway font.
appBar: AppBar(title: Text('Custom Fonts')),
body: Center(
// This Text widget uses the RobotoMono font.
child: Text(
'Roboto Mono sample',
style: TextStyle(fontFamily: 'RobotoMono'),
),
),
);
请参阅https://flutter.dev/docs/cookbook/design/fonts 上的完整教程。
如果您遇到“错误:无法在 pubspec.yaml 中找到资产条目”问题,请参阅 Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf"。 :)
【讨论】:
以上是关于字体下的意外关键资产((字符串)) - 颤动和飞镖中的移动应用程序错误的主要内容,如果未能解决你的问题,请参考以下文章