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.READ_CONTACTS"/>
|
||||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
<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 INTERNET permission is required for development. Specifically,
|
||||||
the Flutter tool needs it to communicate with the running application
|
the Flutter tool needs it to communicate with the running application
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_contacts/flutter_contacts.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 {
|
class CompositionPage extends StatefulWidget {
|
||||||
const CompositionPage({super.key});
|
const CompositionPage({super.key});
|
||||||
@ -13,7 +14,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
String dialedNumber = "";
|
String dialedNumber = "";
|
||||||
List<Contact> _allContacts = [];
|
List<Contact> _allContacts = [];
|
||||||
List<Contact> _filteredContacts = [];
|
List<Contact> _filteredContacts = [];
|
||||||
final ContactService _contactService = ContactService();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -22,10 +22,12 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchContacts() async {
|
Future<void> _fetchContacts() async {
|
||||||
_allContacts = await _contactService.fetchContacts();
|
if (await FlutterContacts.requestPermission()) {
|
||||||
|
_allContacts = await FlutterContacts.getContacts(withProperties: true);
|
||||||
_filteredContacts = _allContacts;
|
_filteredContacts = _allContacts;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _filterContacts() {
|
void _filterContacts() {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -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) {
|
void _onNumberPress(String number) {
|
||||||
setState(() {
|
setState(() {
|
||||||
dialedNumber += number;
|
dialedNumber += number;
|
||||||
@ -112,18 +143,35 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
color: Colors.green[300],
|
color: Colors.green[300],
|
||||||
size: 20),
|
size: 20),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
final phoneNumber = contact
|
||||||
|
.phones.isNotEmpty
|
||||||
|
? contact.phones.first.number
|
||||||
|
: null;
|
||||||
|
if (phoneNumber != null) {
|
||||||
|
_onCallPress(phoneNumber);
|
||||||
|
} else {
|
||||||
print(
|
print(
|
||||||
'Calling ${contact.displayName}');
|
'${contact.displayName} has no phone number.');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
// Text button
|
// Text button
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.message,
|
icon: Icon(Icons.message,
|
||||||
color: Colors.blue[300],
|
color: Colors.blue[300],
|
||||||
size: 20),
|
size: 20),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
final phoneNumber = contact
|
||||||
|
.phones.isNotEmpty
|
||||||
|
? contact.phones.first.number
|
||||||
|
: null;
|
||||||
|
if (phoneNumber != null) {
|
||||||
|
_onTextPress(phoneNumber); // Text functionality
|
||||||
|
} else {
|
||||||
print(
|
print(
|
||||||
'Texting ${contact.displayName}');
|
'${contact.displayName} has no phone number.');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user