feat: add human-readable SIM name handling and update UI accordingly
Some checks failed
/ mirror (push) Failing after 4s
/ build-stealth (push) Successful in 10m49s
/ build (push) Successful in 10m48s

This commit is contained in:
AlexisDanlos 2025-06-18 19:14:58 +02:00
parent af9ce4fa3c
commit dd12b523cc

View File

@ -6,6 +6,7 @@ import 'package:dialer/domain/services/obfuscate_service.dart';
import 'package:dialer/presentation/common/widgets/username_color_generator.dart';
import 'package:dialer/presentation/common/widgets/sim_selection_dialog.dart';
import 'package:flutter/services.dart';
import 'package:sim_data_new/sim_data.dart';
class CallPage extends StatefulWidget {
final String displayName;
@ -38,9 +39,47 @@ class _CallPageState extends State<CallPage> {
StreamSubscription<Map<String, dynamic>>? _audioStateSubscription;
StreamSubscription<int?>? _simStateSubscription;
bool _isCallActive = true; // Track if call is still active
String? _simName; // Human-readable SIM card name
bool get isNumberUnknown => widget.displayName == widget.phoneNumber;
// Fetch and update human-readable SIM name based on slot
Future<void> _updateSimName(int? simSlot) async {
if (!mounted) return;
if (simSlot != null) {
try {
final simData = await SimDataPlugin.getSimData();
// Find the SIM card matching the slot index, if any
dynamic card;
for (var c in simData.cards) {
if (c.slotIndex == simSlot) {
card = c;
break;
}
}
String name;
if (card != null && card.displayName.isNotEmpty) {
name = card.displayName;
} else if (card != null && card.carrierName.isNotEmpty) {
name = card.carrierName;
} else {
name = 'SIM ${simSlot + 1}';
}
setState(() {
_simName = name;
});
} catch (e) {
setState(() {
_simName = 'SIM ${simSlot + 1}';
});
}
} else {
setState(() {
_simName = null;
});
}
}
@override
void initState() {
super.initState();
@ -48,6 +87,7 @@ class _CallPageState extends State<CallPage> {
_listenToCallState();
_listenToAudioState();
_listenToSimState();
_updateSimName(CallService.getCurrentSimSlot); // Initial SIM name
_setInitialAudioState();
}
@ -130,12 +170,7 @@ class _CallPageState extends State<CallPage> {
void _listenToSimState() {
_simStateSubscription = _callService.simStateStream.listen((simSlot) {
if (mounted) {
setState(() {
// UI will update automatically because we're listening to the stream
// The SIM display will show the new SIM slot
});
}
_updateSimName(simSlot);
});
}
@ -403,8 +438,8 @@ class _CallPageState extends State<CallPage> {
color: Colors.white70,
),
),
// Show SIM information if available
if (CallService.getCurrentSimDisplayName() != null)
// Show SIM information if a SIM slot has been set
if (_simName != null)
Container(
margin: const EdgeInsets.only(top: 4.0),
padding: const EdgeInsets.symmetric(
@ -418,7 +453,8 @@ class _CallPageState extends State<CallPage> {
),
),
child: Text(
CallService.getCurrentSimDisplayName()!,
// Show human-readable SIM name plus slot number
'$_simName (SIM ${CallService.getCurrentSimSlot! + 1})',
style: TextStyle(
fontSize: statusFontSize - 2,
color: Colors.lightBlueAccent,