SizedBox 和 Padding.. 有什么区别吗?

Tha*_*med 5 cross-platform dart flutter

我想在文本“NAME”和“Thashreef”之间留一个空格。所以我使用了填充:EdgeInsets.only(top:10),在视频教程中它是SizedBox(height:10)。这两个功能一样吗?


void main()=> runApp(MaterialApp(
  home: FirstPage()
));

class FirstPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.grey[900],
      appBar: AppBar(
        title: Text('Ninja ID Card'),
        centerTitle: true,
        backgroundColor: Colors.grey[850],
        elevation: 0.0,
      ),
      body: Padding(
        padding: EdgeInsets.fromLTRB(20,30,40,50),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text('NAME',style: TextStyle(
              color:Colors.grey,
              letterSpacing: 2.0),),
            Padding(
              padding: const EdgeInsets.only(top:10),
              child: Text('Thashreef',
                style: TextStyle(
                    color: Colors.yellowAccent,
                    letterSpacing:2.0,fontSize: 28.0,fontWeight: FontWeight.bold)),
            )

          ],
        ),
      ),
    );
  }
}```
Run Code Online (Sandbox Code Playgroud)

Joã*_*res 7

Padding并且SizedBox Widgets不一样。

填充用于Widget在周围或特定侧面上留出空间。

SizedBox不需要有子项Widget,只需设置高度或宽度即可。这意味着它可以用作内部的简单间隔符Widgets,其中包含多个子项,例如RowColumn。您遵循的教程可能就是这种情况。