【问题标题】:Flutter dynamic orientation for each screen每个屏幕的颤动动态方向
【发布时间】:2021-08-02 16:14:40
【问题描述】:

如何为每个屏幕添加动态方向? 我需要我的一些屏幕必须是纵向的,其中一些是横向的...... 我用过

SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight])

SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown,DeviceOrientation.portraitUp])

对于不同的屏幕..但这并不能解决我的问题...第一个定位被添加到所有屏幕...

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    实际上,您所做的是通过定义为用户提供选择方向的选项

    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown,DeviceOrientation.portraitUp])
    

    它始终将当前方向设置为您的设备当前所在的方向,但如果它通过设备本身发生更改,它也允许应用程序使用第二或第三方向。

    您应该做的是将其设置为特定的方向,例如

    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown])
    

    现在,由于您希望不同屏幕的方向不同,您可以使用上述命令设置相同的方向,但在每个屏幕上选择所需的方向。

    同样,如果您想让您的应用更具交互性,那么您始终可以使用以下方式获取当前方向

    MediaQuery.of(context).orientation
    

    然后在每个屏幕上决定是否要更改方向。

    您可以找到更多信息here

    【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2021-01-24
    • 2022-11-13
    • 2022-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2020-10-13
    相关资源
    最近更新 更多