Moh*_*ele 2 android ios dart flutter
在我的 flutter 应用程序中,我想控制 IOS 的 will pop 范围,但它不起作用。我没有按照一些示例建议使用 PageRoute,并且CupertinoWillPopScope包无法正常工作,它会引发anchorpoint. 那么有人可以帮我吗?
我尝试了gestureDetectorIOS,但它没有触发上一页的操作,这正是我想要做的。
if (!Platform.isIOS) {
return WillPopScope(
onWillPop: () async {
timerController.startTimer();
!Navigator.of(context).userGestureInProgress;
return true;
},
child: MyPage(),
);
} else {
return GestureDetector(
onHorizontalDragUpdate: (details) {
int sensitivity = 8;
if (details.delta.dx > sensitivity) {
// Right Swipe
//timerController.startTimer();
} else if (details.delta.dx < -sensitivity) {
//Left Swipe
timerController.startTimer();
}
},
child: MyPage(),
);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
问题尚未解决,请在 GitHub 中找到:这里
我制作了自定义课程,因为WillPopScope它对我有用,我希望它也对您有用。
class MyWillPopScope extends StatelessWidget {
MyWillPopScope({required this.child, this.onWillPop = false, Key? key}) : super(key: key);
final Widget child;
final bool onWillPop;
@override
Widget build(BuildContext context) {
return Platform.isIOS ?
GestureDetector(
onPanUpdate: (details) {
if (details.delta.dx > 0) {
if(onWillPop){
Navigator.of(context).pop();
}
}
},
child: WillPopScope(
onWillPop: ()async{
return false;
},
child: child,
)
)
: WillPopScope(child: child, onWillPop: () async {
return onWillPop;
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4973 次 |
| 最近记录: |