From f440767b3872a82f6d17a06a6206d2436edb151c Mon Sep 17 00:00:00 2001 From: AlexisDanlos Date: Wed, 18 Jun 2025 19:14:58 +0200 Subject: [PATCH] feat: add human-readable SIM name handling and update UI accordingly --- .../presentation/features/call/call_page.dart | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/dialer/lib/presentation/features/call/call_page.dart b/dialer/lib/presentation/features/call/call_page.dart index c6ec56b..5791afc 100644 --- a/dialer/lib/presentation/features/call/call_page.dart +++ b/dialer/lib/presentation/features/call/call_page.dart @@ -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 { StreamSubscription>? _audioStateSubscription; StreamSubscription? _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 _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 { _listenToCallState(); _listenToAudioState(); _listenToSimState(); + _updateSimName(CallService.getCurrentSimSlot); // Initial SIM name _setInitialAudioState(); } @@ -130,12 +170,7 @@ class _CallPageState extends State { 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 { 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 { ), ), 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,