nebula

让您的 Flutter 开发之旅更轻松,提供辅助小部件、工具和抽象。

Dimension 小部件

获取与上下文关联的尺寸(高度和宽度),而不是每次都进行 MediaQuery 操作。

Dimension(
  /// You can omit the context, in which case the
  /// widget will use its own context
  context: context,
  builder: (h, w) {
    return Row(
      children: [
        SizedBox(
          height: h * 0.3,
          width: w * 0.3,
          child: Center(child: Text('A')),
        ),
        SizedBox(
          height: h * 0.3,
          width: w * 0.5,
          child: Center(child: Text('B')),
        ),
        SizedBox(
          height: h * 0.3,
          width: w * 0.2,
          child: Center(child: Text('C')),
        ),
      ],
    );
  },
)

context 参数是可空的,因此如果您跳过它,Dimension 小部件将使用自己的上下文来获取高度和宽度。

FitSize 小部件

此小部件会将您的 widget 拟合到提供的尺寸中。该 widget 被包装在 FittedBox 和 SizedBox 中,并传递了提供的参数。您可以使用它,就像使用 SizedBox 一样,只是内容会拟合到提供的尺寸中。

FitSize(
  height: 250,
  alignment: Alignment.topRight,
  fit: BoxFit.fitWidth,
  clipBehavior: Clip.none,
  child: Text('This is my FitSize'),
),

GitHub

查看 Github