Files
MWClash/lib/widgets/back_scope.dart

36 lines
795 B
Dart
Raw Normal View History

2024-04-30 23:38:49 +08:00
import 'dart:io';
import 'package:fl_clash/state.dart';
2024-04-30 23:38:49 +08:00
import 'package:flutter/widgets.dart';
class BackScope extends StatefulWidget {
2024-04-30 23:38:49 +08:00
final Widget child;
const BackScope({super.key, required this.child});
2024-04-30 23:38:49 +08:00
@override
State<BackScope> createState() => _PopContainerState();
2024-04-30 23:38:49 +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,
onPopInvoked: (_) async {
2024-04-30 23:38:49 +08:00
final canPop = Navigator.canPop(context);
if (canPop) {
Navigator.pop(context);
} else {
await globalState.appController.handleBackOrExit();
2024-04-30 23:38:49 +08:00
}
},
child: widget.child,
);
}
return widget.child;
}
}