import 'package:flutter/cupertino.dart'; class BackButtonNav extends StatelessWidget { final BuildContext context; final Widget child; const BackButtonNav({super.key, required this.context, required this.child}); Future _handleWillPop() async { if (Navigator.canPop(context)) { Navigator.pop(context); return false; } return false; } @override Widget build(BuildContext context) { return WillPopScope(onWillPop: _handleWillPop, child: child); } }