Rebase
This commit is contained in:
parent
21b6b0a29a
commit
b39e612ae7
@ -2,8 +2,6 @@
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import '../../widgets/contact_service.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../call/call.dart';
|
||||
|
||||
class CompositionPage extends StatefulWidget {
|
||||
const CompositionPage({super.key});
|
||||
@ -13,7 +14,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
String dialedNumber = "";
|
||||
List<Contact> _allContacts = [];
|
||||
List<Contact> _filteredContacts = [];
|
||||
final ContactService _contactService = ContactService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -22,9 +22,11 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
}
|
||||
|
||||
Future<void> _fetchContacts() async {
|
||||
_allContacts = await _contactService.fetchContacts();
|
||||
_filteredContacts = _allContacts;
|
||||
setState(() {});
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
_allContacts = await FlutterContacts.getContacts(withProperties: true);
|
||||
_filteredContacts = _allContacts;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
void _filterContacts() {
|
||||
@ -40,6 +42,35 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void _onCallPress(String phoneNumber) async {
|
||||
final uri = Uri(scheme: 'tel', path: phoneNumber);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
// Launch the system dialer in the background
|
||||
launchUrl(uri);
|
||||
|
||||
// Navigate to your custom call page
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CallPage(phoneNumber: phoneNumber),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('Could not launch $uri');
|
||||
}
|
||||
}
|
||||
|
||||
// Function to send an SMS
|
||||
void _onTextPress(String phoneNumber) async {
|
||||
final uri = Uri(scheme: 'sms', path: phoneNumber);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
// Launch the SMS app with the given phone number
|
||||
launchUrl(uri);
|
||||
} else {
|
||||
print('Could not launch SMS to $phoneNumber');
|
||||
}
|
||||
}
|
||||
|
||||
void _onNumberPress(String number) {
|
||||
setState(() {
|
||||
dialedNumber += number;
|
||||
@ -112,18 +143,35 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
color: Colors.green[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
print(
|
||||
'Calling ${contact.displayName}');
|
||||
final phoneNumber = contact
|
||||
.phones.isNotEmpty
|
||||
? contact.phones.first.number
|
||||
: null;
|
||||
if (phoneNumber != null) {
|
||||
_onCallPress(phoneNumber);
|
||||
} else {
|
||||
print(
|
||||
'${contact.displayName} has no phone number.');
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
// Text button
|
||||
IconButton(
|
||||
icon: Icon(Icons.message,
|
||||
color: Colors.blue[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
print(
|
||||
'Texting ${contact.displayName}');
|
||||
final phoneNumber = contact
|
||||
.phones.isNotEmpty
|
||||
? contact.phones.first.number
|
||||
: null;
|
||||
if (phoneNumber != null) {
|
||||
_onTextPress(phoneNumber); // Text functionality
|
||||
} else {
|
||||
print(
|
||||
'${contact.displayName} has no phone number.');
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user