import 'package:flutter/material.dart'; import '../../../../domain/services/block_service.dart'; class BlockedNumbersPage extends StatefulWidget { const BlockedNumbersPage({super.key}); @override _BlockedNumbersPageState createState() => _BlockedNumbersPageState(); } class _BlockedNumbersPageState extends State { List _blockedNumbers = []; bool _loading = true; @override void initState() { super.initState(); _loadBlockedNumbers(); } Future _loadBlockedNumbers() async { final numbers = await BlockService().getBlockedNumbers(); setState(() { _blockedNumbers = numbers; _loading = false; }); } Future _removeBlockedNumber(String number) async { await BlockService().unblockNumber(number); await _loadBlockedNumbers(); } Future _addBlockedNumber(String number) async { await BlockService().blockNumber(number); await _loadBlockedNumbers(); } @override Widget build(BuildContext context) { if (_loading) { return const Scaffold( backgroundColor: Colors.black, body: Center(child: CircularProgressIndicator()), ); } return Scaffold( backgroundColor: Colors.black, appBar: AppBar( title: const Text('Blocked Numbers'), ), body: _blockedNumbers.isEmpty ? const Center( child: Text( 'No blocked numbers', style: TextStyle(color: Colors.white70), ), ) : ListView.builder( itemCount: _blockedNumbers.length, itemBuilder: (context, index) { return ListTile( title: Text( _blockedNumbers[index], style: const TextStyle(color: Colors.white), ), trailing: IconButton( icon: const Icon(Icons.delete, color: Colors.red), onPressed: () => _removeBlockedNumber(_blockedNumbers[index]), ), ); }, ), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add), onPressed: () { showDialog( context: context, builder: (BuildContext context) { final TextEditingController controller = TextEditingController(); return AlertDialog( backgroundColor: Colors.grey[900], title: const Text('Block a Number', style: TextStyle(color: Colors.white)), content: TextField( controller: controller, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( hintText: 'Enter phone number', hintStyle: TextStyle(color: Colors.grey), ), keyboardType: TextInputType.phone, ), actions: [ TextButton( child: const Text('Cancel'), onPressed: () => Navigator.of(context).pop(), ), TextButton( child: const Text('Block'), onPressed: () { if (controller.text.trim().isNotEmpty) { _addBlockedNumber(controller.text.trim()); Navigator.of(context).pop(); } }, ), ], ); }, ); }, ), ); } }