Flutter 之 每日翻译 PreferredSizeWidget

Dart 复制代码
/// An interface for widgets that can return the size this widget would prefer
/// if it were otherwise unconstrained.
///
/// There are a few cases, notably [AppBar] and [TabBar], where it would be
/// undesirable for the widget to constrain its own size but where the widget
/// needs to expose a preferred or "default" size. For example a primary
/// [Scaffold] sets its app bar height to the app bar's preferred height
/// plus the height of the system status bar.
///
/// Widgets that need to know the preferred size of their child can require
/// that their child implement this interface by using this class rather
/// than [Widget] as the type of their `child` property.
///
/// Use [PreferredSize] to give a preferred size to an arbitrary widget.
abstract class PreferredSizeWidget implements Widget {
  /// The size this widget would prefer if it were otherwise unconstrained.
  ///
  /// In many cases it's only necessary to define one preferred dimension.
  /// For example the [Scaffold] only depends on its app bar's preferred
  /// height. In that case implementations of this method can just return
  /// `Size.fromHeight(myAppBarHeight)`.
  Size get preferredSize;
}

An interface for widgets that can return the size this widget would prefer
一个控件接口能够返回它希望的尺寸

if it were otherwise unconstrained
如果他不受约束

There are a few cases
在极少数情况下

notablyAppBar and TabBar, where it would be undesirable for the widget to constrain its own size

特别是AppBarTabBar,小部件不希望约束自己的大小

but where the widget needs to exposea preferred or "default" size.

但小部件需要公开****首选或"默认"大小

For example a primary Scaffold sets its app bar height to the app bar's preferred height plus the height of the system status bar.

例如,主要的Scaffold将其应用栏的高度设置为应用栏的首选高度加上系统状态栏的高度。

Widgets that need to know the preferred size of their child can require that their child implement this interface by using this class rather than Widget as the type of their `child` property

需要知道其子部件的首选大小的小部件可以要求其子部件通过使用这个类而不是Widget作为其'子'属性的类型来实现此接口

Use PreferredSize to give a preferred size to an arbitrarywidget.

使用PreferredSize任意小部件提供首选大小。

The size this widget would prefer if it were otherwise unconstrained.

如果这个控件大小不受约束会采用首选的大小

In many cases it's only necessary to define one preferred dimension.

在大多数情况下,只需要定义一个首选尺寸

For example the Scaffold only depends on its app bar's preferred height

例如在脚手架控件只依赖于它的AppBar的首选高度

In that case implementations of this method can just return `Size.fromHeight(myAppBarHeight)`.

在这种情况下,这个方法的实现可以只返回Size.fromHeight(myAppBarHeight)

相关推荐
张宇Joaquin1 分钟前
灵渠测试工具-urma_perftest
java·开发语言
当战神遇到编程2 分钟前
Java 集合框架详解:Collection 与 List 核心用法
java
nicole bai8 分钟前
dialog封装
前端·javascript·vue.js
高彬17 分钟前
SAP ECC6.0 对接 C# web Services服务
开发语言·前端·c#·sap
等....17 分钟前
Flutter创建
flutter
小江的记录本18 分钟前
【CSS】CSS 核心:盒模型、BFC/IFC、Flex/Grid 布局、响应式布局、移动端适配(附《思维导图》)
前端·css·面试·前端框架·tensorflow·html5·xss
Coodor18 分钟前
BS架构下在前端读写超高频UHF标签
前端·超高频·rfid读写器web插件·uhf标签
张小姐的猫22 分钟前
【C++开发脚手架】 —— Jsoncpp上手
java·linux·开发语言·网络·c++·tcp/ip·udp
一晌小贪欢22 分钟前
python-第20天:关键字参数与不定长参数
java·开发语言·前端·python·数据可视化·函数参数·python办公
我命由我1234524 分钟前
JS Mock(Mock 拦截请求的前提、Mock 使用、关闭 Mock)
开发语言·前端·javascript·前端框架·html·html5·js