admin管理员组文章数量:1289528
In my Flutter app, there's a video player, but I can't control the progress bar slider when it's near the edge of the screen because the system's "Back" gesture gets triggered.
This works in the YouTube app, and I need to implement the same behavior.
I am using the standard Slider widget as the progress bar:
Slider(
value: currentTime,
min: startTime,
max: endTime,
onChanged: myOnChangedCb,
)
I need the system "Back" gesture to work everywhere else on the page but not on the video progress bar — so instead, I can move the slider and adjust the video progress.
I tried using:
GestureDetector(
onHorizontalDragStart: (_) {},
onHorizontalDragUpdate: (_) {},
onHorizontalDragEnd: (_) {},
behavior: HitTestBehavior.opaque,
)
but it doesn't work.
I also tried using
PopScope(canPop: false, child: child)
, but it doesn't work either because the "back" gesture gets blocked for the entire page, not just over the video progress bar. (additionally, the system's "Back" animation is still shown on the side of the screen)
In my Flutter app, there's a video player, but I can't control the progress bar slider when it's near the edge of the screen because the system's "Back" gesture gets triggered.
This works in the YouTube app, and I need to implement the same behavior.
I am using the standard Slider widget as the progress bar:
Slider(
value: currentTime,
min: startTime,
max: endTime,
onChanged: myOnChangedCb,
)
I need the system "Back" gesture to work everywhere else on the page but not on the video progress bar — so instead, I can move the slider and adjust the video progress.
I tried using:
GestureDetector(
onHorizontalDragStart: (_) {},
onHorizontalDragUpdate: (_) {},
onHorizontalDragEnd: (_) {},
behavior: HitTestBehavior.opaque,
)
but it doesn't work.
I also tried using
PopScope(canPop: false, child: child)
, but it doesn't work either because the "back" gesture gets blocked for the entire page, not just over the video progress bar. (additionally, the system's "Back" animation is still shown on the side of the screen)
Share Improve this question asked Feb 20 at 16:15 nilecrocodilenilecrocodile 3952 silver badges11 bronze badges2 Answers
Reset to default 1This is an example, just change onPopInvokedWithResult logic
@override
Widget build(BuildContext context) {
var state = Provider.of<AppState>(context, listen: false);
return PopScope(
canPop: false,
onPopInvokedWithResult: (bool didPop, Object? result) {
if (didPop) return;
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to exit the app?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
SystemNavigator.pop();
},
child: Text('Yes'),
),
],
),
);
},
child: Scaffold(
In the end, I found this article, which states:
Starting with Android Q, simple swipe gestures that start within the systemGestureInsets areas are used by the system for page navigation and may not be delivered to the app.
https://api.flutter.dev/flutter/widgets/MediaQueryData/systemGestureInsets.html
本文标签: Flutter Disable the system Back gesture over the video player progress bar (Slider)Stack Overflow
版权声明:本文标题:Flutter: Disable the system Back gesture over the video player progress bar (Slider)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741422471a2377884.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论