2024-04-30 23:38:49 +08:00
|
|
|
import 'dart:io';
|
2024-05-11 17:02:34 +08:00
|
|
|
import 'package:fl_clash/state.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
class BackScope extends StatefulWidget {
|
2024-04-30 23:38:49 +08:00
|
|
|
final Widget child;
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
const BackScope({super.key, required this.child});
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
@override
|
2024-09-08 21:21:21 +08:00
|
|
|
State<BackScope> createState() => _PopContainerState();
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
class _PopContainerState extends State<BackScope> {
|
2024-04-30 23:38:49 +08:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
return PopScope(
|
|
|
|
|
canPop: false,
|
2024-11-09 20:17:57 +08:00
|
|
|
onPopInvokedWithResult: (_, __) async {
|
2024-04-30 23:38:49 +08:00
|
|
|
final canPop = Navigator.canPop(context);
|
|
|
|
|
if (canPop) {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} else {
|
2024-05-11 17:02:34 +08:00
|
|
|
await globalState.appController.handleBackOrExit();
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: widget.child,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return widget.child;
|
|
|
|
|
}
|
|
|
|
|
}
|