【问题标题】: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],
    ),
  ),
));

【问题讨论】:

    标签: flutter android-studio


    【解决方案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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-28
        • 2020-12-22
        • 2021-07-04
        • 1970-01-01
        • 2020-11-08
        • 2020-11-19
        • 2019-12-18
        • 1970-01-01
        相关资源
        最近更新 更多