Files
MWClash/lib/widgets/pop_scope.dart
chen08209 f06abecb3e Add android separates the core process
Support core status check and force restart

Optimize proxies page and access page

Update flutter and pub dependencies
2025-09-03 10:08:26 +08:00

76 lines
1.7 KiB
Dart

import 'dart:async';
import 'package:fl_clash/state.dart';
import 'package:flutter/widgets.dart';
class CommonPopScope extends StatelessWidget {
final Widget child;
final FutureOr<bool> Function()? onPop;
final FutureOr<void> Function()? onPopSuccess;
const CommonPopScope({
super.key,
required this.child,
this.onPop,
this.onPopSuccess,
});
@override
Widget build(BuildContext context) {
return PopScope(
canPop: onPop == null ? true : false,
onPopInvokedWithResult: onPop == null
? null
: (didPop, _) async {
if (didPop) {
return;
}
final res = await onPop!();
if (!context.mounted) {
return;
}
if (!res) {
return;
}
Navigator.of(context).pop();
if (onPopSuccess != null) {
await onPopSuccess!();
}
},
child: child,
);
}
}
class SystemBackBlock extends StatefulWidget {
final Widget child;
const SystemBackBlock({super.key, required this.child});
@override
State<SystemBackBlock> createState() => _SystemBackBlockState();
}
class _SystemBackBlockState extends State<SystemBackBlock> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
globalState.appController.backBlock();
});
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.addPostFrameCallback((_) {
globalState.appController.unBackBlock();
});
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}