【问题标题】:Any tips on how I would render widgets based on phone direction?关于如何根据手机方向呈现小部件的任何提示?
【发布时间】:2018-03-31 20:02:29
【问题描述】:

如果手机的主要方向是垂直的,我希望这两个项目出现在一个列中,如果手机的方向是水平的,我希望这两个项目出现在一行中。

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    MediaQuery.of(context) 会给你方向,等等。 API docs here.

    例如,在您的 build() 方法内部:

    var columnCount =
              MediaQuery.of(context).orientation == Orientation.portrait ? 2 : 4;
    

    【讨论】:

      猜你喜欢
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2013-01-10
      相关资源
      最近更新 更多