飘动铰链感知弹出路由

当应用程序跨 Surface Duo 时,对话框将出现在第一个屏幕上,即从左到右配置的左侧屏幕。 方法上的showDialog可选参数anchorPoint允许重写此行为。 默认情况下,弹出菜单避免使用铰链。 如果代码具有自定义模式路由,则可以使用 DisplayFeatureSubScreen 将其包装,以避免铰链重叠。

默认情况下,此对话框显示在左侧屏幕上,用于从左到右的配置,从右到左的配置显示在右侧屏幕上:

showDialog(
    context: context,
    builder: (_) => AlertDialog(
        title: Text("Hinge Aware Dialog"),
        content: Text("Going on the left screen"),
    ),
);

左侧屏幕上的 Surface Duo Flutter 对话框

可以使用 参数强制对话进入右侧屏幕 anchorPoint 。 此函数类似于可用于选择所需屏幕的目标:

showDialog(
    context: context,
    builder: (_) => AlertDialog(
        title: Text("Hinge Aware Dialog"),
        content: Text("Going on the right screen"),
    ),
    anchorPoint: Offset(1000, 1000),
);

右侧屏幕上的 Surface Duo Flutter 对话框

自定义路由

你可能在应用中有自己的模式或弹出路由类,你希望使铰链感知。 使用 DisplayFeatureSubScreen 小组件包装模式路由。 将其添加到路线布局的顶部,使其避免铰链。 此小组件还采用 参数 anchorPoint

class _MyRoute<T> extends PopupRoute<T> {
    @override
    Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
        return DisplayFeatureSubScreen(
            child: _myPageLayout(), // the previous content of buildPage
            anchorPoint: Offset.infinite,
        );
    }
}