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 badges
Add a comment  | 

2 Answers 2

Reset to default 1

This 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