【问题标题】:How to get the autorotate setting status with Flutter?如何使用 Flutter 获取自动旋转设置状态?
【发布时间】:2021-07-29 10:00:21
【问题描述】:

想在 Flutter 应用程序中获取“自动旋转”系统设置的当前状态。需要确定天气是开启还是关闭。

这可以通过stackoverflow问题中提到的答案在android中完成。 Android auto rotate on off status link。但是 Flutter 需要同样的功能,它应该适用于 android 和 ios。

采纳您的建议。

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    要知道屏幕的Orientation,可以使用OrientationBuilder Widget,它会判断当前的Orientation,并在Orientation改变状态时重建。

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: OrientationBuilder(builder: (_, orientation) {
          if (orientation == Orientation.portrait)
            return Something(); // if orientation is portrait, do something
          else
            return Something(); // else do something 
        }),
      );
    }
    

    【讨论】:

    • 感谢您的回复。我需要知道打开或关闭“自动旋转”系统设置。基于此,我有一些工作要做。
    • 你必须在本地这样做
    猜你喜欢
    • 2012-06-03
    • 2021-06-25
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2017-08-06
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多