import 'package:flutter/material.dart'; import 'package:mobile_number/mobile_number.dart'; class ChooseSimPage extends StatefulWidget { const ChooseSimPage({Key? key}) : super(key: key); @override _ChooseSimPageState createState() => _ChooseSimPageState(); } class _ChooseSimPageState extends State { List _simCards = []; int? _selectedSimIndex; @override void initState() { super.initState(); _fetchSimCards(); } Future _fetchSimCards() async { try { bool permissionsGranted = await MobileNumber.hasPhonePermission; if (!permissionsGranted) { await MobileNumber.requestPhonePermission; permissionsGranted = await MobileNumber.hasPhonePermission; } if (permissionsGranted) { List? simCards = await MobileNumber.getSimCards; if (simCards != null && mounted) { setState(() { _simCards = simCards; _selectedSimIndex = 0; }); } else { print('No SIM cards found'); } } else { print('Phone permission denied'); } } catch (e) { print('Failed to get SIM cards: $e'); } } void _onSimSelected(int? index) { if (index != null) { setState(() { _selectedSimIndex = index; }); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, appBar: AppBar( title: const Text('Choose SIM'), ), body: _simCards.isEmpty ? const Center( child: Text( 'No SIM cards found', style: TextStyle(color: Colors.white), ), ) : ListView.builder( itemCount: _simCards.length, itemBuilder: (context, index) { final sim = _simCards[index]; return ListTile( title: Text( 'SIM ${index + 1}', style: const TextStyle(color: Colors.white), ), subtitle: Text( 'Operator: ${sim.carrierName ?? 'N/A'}', style: const TextStyle(color: Colors.grey), ), trailing: Radio( value: index, groupValue: _selectedSimIndex, onChanged: _onSimSelected, ), ); }, ), ); } }