feat: ensure call page closes on hangup and disconnection, improving navigation flow
All checks were successful
/ mirror (push) Successful in 4s
/ build (push) Successful in 10m39s
/ build-stealth (push) Successful in 10m38s

This commit is contained in:
AlexisDanlos 2025-07-03 16:02:38 +02:00
parent 9d4fefe8ff
commit 4f0028d73f
2 changed files with 51 additions and 31 deletions

View File

@ -101,18 +101,15 @@ class CallService {
print('CallService: _manualHangupFlag: $_manualHangupFlag'); print('CallService: _manualHangupFlag: $_manualHangupFlag');
print('CallService: _isCallPageVisible: $_isCallPageVisible'); print('CallService: _isCallPageVisible: $_isCallPageVisible');
// Close call page if no pending SIM switch OR if it was a manual hangup // Always close call page on disconnection - SIM switching should not prevent this
if (_pendingSimSwitch == null || _manualHangupFlag) { print('CallService: Calling _closeCallPage() on call disconnection');
print('CallService: Condition met, calling _closeCallPage()'); _closeCallPage();
_closeCallPage();
// Only reset manual hangup flag after successful page close // Reset manual hangup flag after successful page close
if (_manualHangupFlag) { if (_manualHangupFlag) {
print( print(
'CallService: Resetting manual hangup flag after page close'); 'CallService: Resetting manual hangup flag after page close');
_manualHangupFlag = false; _manualHangupFlag = false;
}
} else {
print('CallService: NOT closing call page - condition not met');
} }
if (wasPhoneLocked) { if (wasPhoneLocked) {
await _channel.invokeMethod("callEndedFromFlutter"); await _channel.invokeMethod("callEndedFromFlutter");
@ -169,18 +166,15 @@ class CallService {
print('CallService: _manualHangupFlag: $_manualHangupFlag'); print('CallService: _manualHangupFlag: $_manualHangupFlag');
print('CallService: _isCallPageVisible: $_isCallPageVisible'); print('CallService: _isCallPageVisible: $_isCallPageVisible');
// Only close call page if there's no pending SIM switch OR if it was a manual hangup during SIM switch // Always close call page when call ends - SIM switching should not prevent this
if (_pendingSimSwitch == null || _manualHangupFlag) { print('CallService: Calling _closeCallPage() on call ended/removed');
print('CallService: Condition met, calling _closeCallPage()'); _closeCallPage();
_closeCallPage();
// Reset manual hangup flag after closing page // Reset manual hangup flag after closing page
if (_manualHangupFlag) { if (_manualHangupFlag) {
print( print(
'CallService: Resetting manual hangup flag after callEnded'); 'CallService: Resetting manual hangup flag after callEnded');
_manualHangupFlag = false; _manualHangupFlag = false;
}
} else {
print('CallService: NOT closing call page - condition not met');
} }
if (wasPhoneLocked) { if (wasPhoneLocked) {
await _channel.invokeMethod("callEndedFromFlutter"); await _channel.invokeMethod("callEndedFromFlutter");
@ -490,13 +484,22 @@ class CallService {
print( print(
'CallService: Closing call page, _isCallPageVisible: $_isCallPageVisible, _pendingSimSwitch: ${_pendingSimSwitch != null}, _manualHangupFlag: $_manualHangupFlag'); 'CallService: Closing call page, _isCallPageVisible: $_isCallPageVisible, _pendingSimSwitch: ${_pendingSimSwitch != null}, _manualHangupFlag: $_manualHangupFlag');
if (Navigator.canPop(context)) {
print('CallService: Popping call page'); // Use popUntil to ensure we go back to the home page
Navigator.pop(context); try {
_isCallPageVisible = false; Navigator.popUntil(context, (route) => route.isFirst);
} else {
print('CallService: No page to pop, setting _isCallPageVisible to false');
_isCallPageVisible = false; _isCallPageVisible = false;
print('CallService: Used popUntil to return to home page');
} catch (e) {
print('CallService: Error with popUntil, trying regular pop: $e');
if (Navigator.canPop(context)) {
Navigator.pop(context);
_isCallPageVisible = false;
print('CallService: Used regular pop as fallback');
} else {
print('CallService: No page to pop, setting _isCallPageVisible to false');
_isCallPageVisible = false;
}
} }
_activeCallNumber = null; _activeCallNumber = null;
} }

View File

@ -319,7 +319,7 @@ class _CallPageState extends State<CallPage> {
print( print(
'CallPage: Initiating manual hangUp - canceling any pending SIM switch'); 'CallPage: Initiating manual hangUp - canceling any pending SIM switch');
// Immediately mark call as inactive to allow page navigation // Immediately mark call as inactive to prevent further interactions
setState(() { setState(() {
_isCallActive = false; _isCallActive = false;
_callStatus = "Ending Call..."; _callStatus = "Ending Call...";
@ -330,6 +330,12 @@ class _CallPageState extends State<CallPage> {
final result = await _callService.hangUpCall(context); final result = await _callService.hangUpCall(context);
print('CallPage: Hang up result: $result'); print('CallPage: Hang up result: $result');
// If the page is still visible after hangup, try to close it
if (mounted && ModalRoute.of(context)?.isCurrent == true) {
print('CallPage: Still visible after hangup, navigating back');
Navigator.of(context).popUntil((route) => route.isFirst);
}
} catch (e) { } catch (e) {
print('CallPage: Error hanging up: $e'); print('CallPage: Error hanging up: $e');
if (mounted) { if (mounted) {
@ -367,6 +373,17 @@ class _CallPageState extends State<CallPage> {
print( print(
'CallPage: Building UI, _callStatus: $_callStatus, route: ${ModalRoute.of(context)?.settings.name ?? "unknown"}'); 'CallPage: Building UI, _callStatus: $_callStatus, route: ${ModalRoute.of(context)?.settings.name ?? "unknown"}');
// If call is disconnected and we're not actively navigating, force navigation
if ((_callStatus == "Call Ended" || !_isCallActive) && mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && ModalRoute.of(context)?.isCurrent == true) {
print('CallPage: Call ended, forcing navigation back to home');
Navigator.of(context).popUntil((route) => route.isFirst);
}
});
}
return PopScope( return PopScope(
canPop: canPop:
true, // Always allow popping - CallService manages when it's appropriate true, // Always allow popping - CallService manages when it's appropriate