Flutter WillPopScope禁用向左滑动以在IOS中返回

问题描述 投票:0回答:2

我在flutter应用程序中使用WillPopScope,它禁用了在IOS中非常有用的“向左轻扫以返回”。如何保留WillPopScope但重新添加iOS手势?

ios flutter dart gesture
2个回答
0
投票

如果我理解正确,您不希望Android用户使用后退按钮,但是ios用户可以使用向左滑动手势。 (因为ios用户没有后退按钮)。

在这种情况下,您可以将willpopscope(false或true)设置为变量。

并且在initstate中,您可以创建定义平台的函数:

import 'dart:io' show Platform;

if (Platform.isAndroid) {
  // Android-specific code
  // here you can set the variable to true
} else if (Platform.isIOS) {
  // iOS-specific code
  // here you can set the variable to false

}

如果您不想禁用appBar上的后退按钮,那是appBar内的另一行代码。


0
投票

为了控制您的行为,willpopscope。您可以将true或false设为变量。

  onWillPop: () async => false,

带有一个变量,它将是:

bool myVariable = false;

  onWillPop: () async => myVariable,

要更改行为,您可以创建一个使用SetState更改“ myVariable”的函数。

© www.soinside.com 2019 - 2024. All rights reserved.