From 05e7f502697ea85f6034da4a94b90720c0670a0e Mon Sep 17 00:00:00 2001 From: Florian Griffon Date: Sun, 15 Dec 2024 02:32:18 +0100 Subject: [PATCH] fix: composition doesn't ask permissions twice --- .../lib/features/composition/composition.dart | 59 ++++++++++++------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/dialer/lib/features/composition/composition.dart b/dialer/lib/features/composition/composition.dart index 783fcf9..b224f05 100644 --- a/dialer/lib/features/composition/composition.dart +++ b/dialer/lib/features/composition/composition.dart @@ -22,11 +22,9 @@ class _CompositionPageState extends State { } Future _fetchContacts() async { - if (await FlutterContacts.requestPermission()) { - _allContacts = await _contactService.fetchContacts(); - _filteredContacts = _allContacts; - setState(() {}); - } + _allContacts = await _contactService.fetchContacts(); + _filteredContacts = _allContacts; + setState(() {}); } void _filterContacts() { @@ -81,9 +79,9 @@ class _CompositionPageState extends State { // Top half: Display contacts matching dialed number Expanded( flex: 2, - child: - Container( - padding: const EdgeInsets.only(top: 42.0, left: 16.0, right: 16.0, bottom: 16.0), + child: Container( + padding: const EdgeInsets.only( + top: 42.0, left: 16.0, right: 16.0, bottom: 16.0), color: Colors.black, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -95,12 +93,14 @@ class _CompositionPageState extends State { return ListTile( title: Text( contact.displayName, - style: const TextStyle(color: Colors.white), + style: + const TextStyle(color: Colors.white), ), subtitle: contact.phones.isNotEmpty ? Text( contact.phones.first.number, - style: const TextStyle(color: Colors.grey), + style: const TextStyle( + color: Colors.grey), ) : null, trailing: Row( @@ -108,16 +108,22 @@ class _CompositionPageState extends State { children: [ // Call button IconButton( - icon: Icon(Icons.phone, color: Colors.green[300], size: 20), + icon: Icon(Icons.phone, + color: Colors.green[300], + size: 20), onPressed: () { - print('Calling ${contact.displayName}'); + print( + 'Calling ${contact.displayName}'); }, ), // Text button IconButton( - icon: Icon(Icons.message, color: Colors.blue[300], size: 20), + icon: Icon(Icons.message, + color: Colors.blue[300], + size: 20), onPressed: () { - print('Texting ${contact.displayName}'); + print( + 'Texting ${contact.displayName}'); }, ), ], @@ -127,7 +133,12 @@ class _CompositionPageState extends State { }, ); }).toList() - : [Center(child: Text('No contacts found', style: TextStyle(color: Colors.white)))], + : [ + Center( + child: Text('No contacts found', + style: + TextStyle(color: Colors.white))) + ], ), ), ], @@ -152,14 +163,16 @@ class _CompositionPageState extends State { alignment: Alignment.center, child: Text( dialedNumber, - style: const TextStyle(fontSize: 24, color: Colors.white), + style: const TextStyle( + fontSize: 24, color: Colors.white), overflow: TextOverflow.ellipsis, ), ), ), IconButton( onPressed: _onClearPress, - icon: const Icon(Icons.backspace, color: Colors.white), + icon: const Icon(Icons.backspace, + color: Colors.white), ), ], ), @@ -172,7 +185,8 @@ class _CompositionPageState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, children: [ _buildDialButton('1'), _buildDialButton('2'), @@ -180,7 +194,8 @@ class _CompositionPageState extends State { ], ), Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, children: [ _buildDialButton('4'), _buildDialButton('5'), @@ -188,7 +203,8 @@ class _CompositionPageState extends State { ], ), Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, children: [ _buildDialButton('7'), _buildDialButton('8'), @@ -196,7 +212,8 @@ class _CompositionPageState extends State { ], ), Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, children: [ _buildDialButton('*'), _buildDialButton('0'),