如何在 Dart 中增加字体大小

Mac*_*caw 9 dart flutter

我是 Flutter+Dart 的新手,并试图增加字体大小,但很难理解文档 + 实现我的工作。这是文件。我该如何解决我的问题?

import 'package:flutter/material.dart';

void main() => runApp(NewApp());



class NewApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('App Header'),
        ),
        body:  new Column(
          children: [
            new Container(
              margin: new EdgeInsets.all(10.0),
              child: new Card(
                child: new Column(
                  children: <Widget>[
                    new Container(
                      padding: new EdgeInsets.all(10.0),
                      child: new Text('Hello Macaw'),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 12

一开始,这很难理解和实施。但是一旦你理解了,你就会爱上 Flutter 框架。这是解决方案:

new Text('Hello Macaw',style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),),
Run Code Online (Sandbox Code Playgroud)

之后,格式化代码。就是这样。让我知道它是否有效。


Cop*_*oad 6

您可以使用 的style属性Text来更改 的某些属性Text

例子:

Text(
    "Your text",
     style: TextStyle(
      fontSize: 20.0,
      color: Colors.red,
      fontWeight: FontWeight.w600,
    ),
  )
Run Code Online (Sandbox Code Playgroud)

使用预定义styleText您提供标准fontSizefontWeightText.

你可以像这样使用它们

style: Theme.of(context).textTheme.XYZ
Run Code Online (Sandbox Code Playgroud)

XYZ可以是body1body2titlesubheadheadline等。