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
在极少数情况下

notably[AppBar] and [TabBar], where it would be undesirable for the widget to constrain its own size

特别是[AppBar]和[TabBar],小部件不希望约束自己的大小

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)

相关推荐
猫头虎-前端技术12 分钟前
浏览器兼容性问题全解:CSS 前缀、Grid/Flex 布局兼容方案与跨浏览器调试技巧
前端·css·node.js·bootstrap·ecmascript·css3·媒体
阿珊和她的猫12 分钟前
探索 CSS 过渡:打造流畅网页交互体验
前端·css
元亓亓亓12 分钟前
JavaWeb--day1--HTML&CSS
前端·css·html
β添砖java12 分钟前
CSS的文本样式
前端·css
前端小趴菜0513 分钟前
css - 滤镜
前端·css
祈祷苍天赐我java之术13 分钟前
理解 CSS 浮动技术
前端·css
索迪迈科技15 分钟前
Flex布局——详解
前端·html·css3·html5
咔咔一顿操作17 分钟前
【CSS 3D 实战】从零实现旋转立方体:理解 3D 空间的核心原理
前端·css·3d·css3
敲键盘的肥嘟嘟左卫门18 分钟前
StringBuilder类的数据结构和扩容方式解读
java
DONG91319 分钟前
深度解析CSS单位与媒体查询:构建现代化响应式布局的核心技术
前端·css·html·css3·媒体