【问题标题】:How to set left and top in a Positioned widget in pixels or any other units in Flutter/Dart?如何以像素或 Flutter/Dart 中的任何其他单位在 Positioned 小部件中设置 left 和 top?
【发布时间】:2021-09-25 05:13:52
【问题描述】:

如何在 Flutter/Dart 中以像素或任何其他单位设置 Positioned 小部件的左侧和顶部?

left 和 top 值的单位是什么?它们是百分比还是独立像素或其他什么?如果不是,它使用什么单位?

【问题讨论】:

标签: flutter dart flutter-positioned


【解决方案1】:

例子:

Stack(
  alignment: Alignment.center,
  children: [
    Container(
       height: 200,
       width: 200,
       color: Colors.red,
    ),
    // postion will be based on up Container Widget
    // position top left
    const Positioned(
       left: 0,
       top: 0,
       child: CircleAvatar(
           backgroundColor: Colors.blue,
       ),
    ),
    // position bottom right
    const Positioned(
        bottom: 0,
        right: 0,
        child: CircleAvatar(
           backgroundColor: Colors.blue,
        ),
     ),
  ],
),

如果你不给出任何立场。该位置将基于堆栈对齐。

【讨论】:

  • 哦,非常感谢您的代码!有什么办法可以得到屏幕大小?我尝试使用 MediaQuery 但没有用。我返回了一个 MaterialApp,但我仍然无法使用构建上下文。
猜你喜欢
  • 2021-09-09
  • 2020-10-10
  • 2020-02-16
  • 2011-10-16
  • 1970-01-01
  • 1970-01-01
  • 2019-05-28
  • 2021-08-26
  • 1970-01-01
相关资源
最近更新 更多