颤振给我错误(不知道为啥)(使用颤振和Android Studio)

Posted

技术标签:

【中文标题】颤振给我错误(不知道为啥)(使用颤振和Android Studio)【英文标题】:flutter giving me error (dont know why) (using flutter and Android Studio)颤振给我错误(不知道为什么)(使用颤振和Android Studio) 【发布时间】:2021-07-02 14:20:53 【问题描述】:

这是代码:(请回复我似乎找不到的错误

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  home: Scaffold(
    appBar: AppBar(
      title: Text('MyApp'),
      centerTitle: true,
      backgroundColor: Colors.cyan[300],
    ),
    body: Center(
      child: Text(
        'This is MyApp',
        style: TextStyle(
          fontSize: 20.0,
            fontWeight: FontWeight.bold,
          letterSpacing: 2.0,
          color: Colors.blueGrey,
          fontFamily:
        ),
      ),
    ),
    floatingActionButton: FloatingActionButton(
      onPressed: () ,
      child: Text('  CLICK!'),
      backgroundColor: Colors.cyan[300],
    ),
  ),
));

【问题讨论】:

【参考方案1】:

您忘记添加字体系列值。

示例:fontFamily: 'Raleway'

更新代码

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('MyApp'),
          centerTitle: true,
          backgroundColor: Colors.cyan[300],
        ),
        body: Center(
          child: Text(
            'This is MyApp',
            style: TextStyle(
              fontSize: 20.0,
              fontWeight: FontWeight.bold,
              letterSpacing: 2.0,
              color: Colors.blueGrey,
              fontFamily: 'Raleway',
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () ,
          child: Text(' CLICK!'),
          backgroundColor: Colors.cyan[300],
        ),
      ),
    ));

Use a custom font - Flutter

【讨论】:

【参考方案2】:

您尚未定义 fontFamily 值。 您必须先导入字体,然后才能定义它。 用于设置自定义字体。

按照此步骤添加自定义字体 - https://flutter.dev/docs/cookbook/design/fonts

请让你的代码看起来干净简单,或者这样发布。

【讨论】:

以上是关于颤振给我错误(不知道为啥)(使用颤振和Android Studio)的主要内容,如果未能解决你的问题,请参考以下文章

为啥颤振本地通知会出现异常

为啥在颤振项目中添加启动器图标时出现错误?

如何在颤振中解析json?

为啥颤振向我显示此错误,我该如何解决?

每次我运行任何应用程序时,颤振都会给我错误

一个奇怪的颤振错误,我不知道如何解决