Custom WillPopScope – Flutter

The WillPopScope widget comes with the Flutter framework. It gives us control over the back button action, allowing the current page to go back to the previous one if it meets certain requirements. This is achieved using a callback, which the widget takes in as one of its parameters.

How to overcome iOS limitations in Flutter willpopscope. If Willpopscope is used in iOS, default swipe navigations will not work in iOS.

Below code will help you on this

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CustomWillPop extends StatelessWidget {
  final Widget child;
  final Future<bool> Function() onWillPop;

  const CustomWillPop(
      {super.key, required this.child, required this.onWillPop});
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: onWillPop,
        child: Platform.isIOS
            ? GestureDetector(
                onPanEnd: (details) {
                  if (details.velocity.pixelsPerSecond.dx < 0 ||
                      details.velocity.pixelsPerSecond.dx > 0) {
                    onWillPop();

                    // Code for iOS
                    //Get.back();
                  }
                },
                child: child)
            : child);
  }
}