dart 支架和容器在Flutter中的区别是什么?

fnvucqvd  于 2022-12-06  发布在  Flutter
关注(0)|答案(7)|浏览(169)

我知道Scaffold和Container都是Flutter中的父部件,但是我应该在什么时候使用Scaffold,什么时候使用Container来布局我的子部件?

z4bn682m

z4bn682m1#

Scaffoldcontainer用于不同的布局和设计目的。

脚手架

  • 实现了基本材质设计的可视化布局结构。
  • 此类提供用于显示抽屉、小吃店和底部薄片的API。

链接-Scaffold

容器

  • 一个方便的小部件,它结合了常用的绘画、定位和调整大小小部件。
  • 它基本上包含不同的小部件到一个小部件,你可以给予填充,大小,位置等。

链接-Container

结论

您需要Scaffold小部件作为您的页面的主要父级,您可以使用容器将较小的小部件放入页面中,以给予它们不同的属性,如大小、边框、填充、边距等。

wqlqzqxt

wqlqzqxt2#

I would recommend you should understand MaterialApp Widget for a better understanding of Material Widgets like Scaffold and Container.

Scaffold:

The scaffold is the MaterialApp Widget which gives us pre-defined properties like AppBar, Body, Bottom Navigation, Floating Action & Persistent Footer. The scaffold will give Material look and feel in Screen.
Ideally, in MaterialApp every page/Screen will consist of the parent widget as a scaffold. If we don't give Scaffold as a parent widget there will be no material look and feel in Material App.

Helpful link for Scaffold Widget:

Scaffold Class: https://api.flutter.dev/flutter/material/Scaffold-class.html
App Samples: https://flutter.dev/docs/catalog/samples/Scaffold

Container:

The container is a basic/common widget in Flutter which will contain other widgets. Container widget used for decorating its child widget. we can give properties like borders, padding, alignment, height, width, etc. The container class will only contain one child widget.

Helpful link for Container Widget:

Container Class: https://api.flutter.dev/flutter/widgets/Container-class.html

uxhixvfz

uxhixvfz3#

Scaffold is like a parent widget or just consider a whole where you would have different properties like appbar,body all those type widgets are child widget scaffold gives better look to app where only using container is much uglier

Scaffold:

The scaffold has AppBar, Body, Bottom Navigation, Floating Action & Persistent Footer. The scaffold will give Material look and feel in Screen.

Container:

The container is a basic/common widget in Flutter which will contain other widgets. we can give padding , size , position etc.

bbmckpt7

bbmckpt74#

Scaffold是Activity/UIView/Screen的布局结构。比方说,一个应用程序有一个通用的屏幕流程,如appbar,layouts,bottomnavigation bar,drawer,floating action button和更多的视图,无论它是Android/iOS平台的应用程序。
Scaffold会给予你一个默认的结构属性,比如appbar,body,floatingaction button,drawer等等,以减少你为你的应用Activity/screen/page/UIView创建一个新的自定义结构的麻烦。
虽然容器是一个灵活的小部件,具有任何视图都需要的通用属性。您也可以使用自己的逻辑和解决方案,在容器小部件的帮助下创建任何类型的自定义小部件。
我认为容器是最兼容的小部件,它可以与几乎每一个小部件一起工作。

eaf3rand

eaf3rand5#

Scaffold示例化我们的主结构,通常是应用中一致的结构,如应用栏或导航,然后我们将主体设置为应用中更有趣的部分,将其从runApp中抽象出来,这也允许我们使用热重载。
就像HTML div一样,我们可以 Package 容器,以便在我们无法操作它们的时候对元素给予更多的控制,因为并不是每个小部件都有像width或padding这样的属性。容器有一些与CSS相同的属性,比如height、width、padding和margin。默认情况下,它们会占用其子元素的最大空间。空容器试图占用其父容器的最大空间量。

bakd9h0s

bakd9h0s6#

From wikipedia, Scaffolding means:
Scaffolding, also called scaffold or staging, is a temporary structure used to support a work crew and materials to aid in the construction, maintenance and repair of buildings, bridges and all other man made structures. Scaffolds are widely used on site to get access to heights and areas that would be otherwise hard to get to. Unsafe scaffolding has the potential to result in death or serious injury. Scaffolding is also used in adapted forms for formwork and shoring, grandstand seating, concert stages, access/viewing towers, exhibition stands, ski ramps, half pipes and art projects.
In Flutter, you're Scaffolding/preparing your app basic building block by using the Scaffold widget.
From the documentation :
Scaffold class
Implements the basic material design visual layout structure.
This class provides APIs for showing drawers, snack bars, and bottom sheets.
When you're building an app, you need some widgets as the building block for your app. The Container is one of the building block.
In short: Scaffold is the app, Container is one of the part needed to create the app.

r8xiu3jd

r8xiu3jd7#

容器=〉
容器类只包含一个子部件在容器类中,我们可以使用一些属性来修饰我们部件,例如:高度、宽度、填充、颜色、对齐等。

相关问题