88 lines
2.1 KiB
Dart
88 lines
2.1 KiB
Dart
// chooseSim.dart
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:sim_data/sim_data.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
class ChooseSimPage extends StatefulWidget {
|
|
const ChooseSimPage({super.key});
|
|
|
|
@override
|
|
_ChooseSimPageState createState() => _ChooseSimPageState();
|
|
}
|
|
|
|
class _ChooseSimPageState extends State<ChooseSimPage> {
|
|
List<SimCard> _simCards = [];
|
|
int? _selectedSimIndex;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_fetchSimCards();
|
|
}
|
|
|
|
Future<void> _fetchSimCards() async {
|
|
if (await Permission.phone.request().isGranted) {
|
|
try {
|
|
final simData = await SimDataPlugin.getSimData();
|
|
setState(() {
|
|
_simCards = simData.cards;
|
|
_selectedSimIndex = 0;
|
|
});
|
|
} catch (e) {
|
|
// Handle error
|
|
print('Error fetching SIM data: $e');
|
|
}
|
|
} else {
|
|
// Permission denied
|
|
print('Phone permission denied');
|
|
}
|
|
}
|
|
|
|
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('Choisir la SIM'),
|
|
),
|
|
body: _simCards.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'Aucune carte SIM trouvée',
|
|
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(
|
|
'Opérateur: ${sim.carrierName}',
|
|
style: const TextStyle(color: Colors.grey),
|
|
),
|
|
trailing: Radio<int>(
|
|
value: index,
|
|
groupValue: _selectedSimIndex,
|
|
onChanged: _onSimSelected,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|