feat: rebase from contact-modal branch
This commit is contained in:
parent
bf8e13aa09
commit
b072f8fff5
@ -2,6 +2,8 @@
|
||||
<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,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../call/call.dart';
|
||||
import '../../widgets/contact_service.dart';
|
||||
|
||||
class CompositionPage extends StatefulWidget {
|
||||
const CompositionPage({super.key});
|
||||
@ -14,6 +13,7 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
String dialedNumber = "";
|
||||
List<Contact> _allContacts = [];
|
||||
List<Contact> _filteredContacts = [];
|
||||
final ContactService _contactService = ContactService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -22,11 +22,9 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
}
|
||||
|
||||
Future<void> _fetchContacts() async {
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
_allContacts = await FlutterContacts.getContacts(withProperties: true);
|
||||
_filteredContacts = _allContacts;
|
||||
setState(() {});
|
||||
}
|
||||
_allContacts = await _contactService.fetchContacts();
|
||||
_filteredContacts = _allContacts;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _filterContacts() {
|
||||
@ -42,35 +40,6 @@ 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;
|
||||
@ -143,35 +112,18 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
color: Colors.green[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
final phoneNumber = contact
|
||||
.phones.isNotEmpty
|
||||
? contact.phones.first.number
|
||||
: null;
|
||||
if (phoneNumber != null) {
|
||||
_onCallPress(phoneNumber);
|
||||
} else {
|
||||
print(
|
||||
'${contact.displayName} has no phone number.');
|
||||
}
|
||||
print(
|
||||
'Calling ${contact.displayName}');
|
||||
},
|
||||
),
|
||||
|
||||
// Text button
|
||||
IconButton(
|
||||
icon: Icon(Icons.message,
|
||||
color: Colors.blue[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
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.');
|
||||
}
|
||||
print(
|
||||
'Texting ${contact.displayName}');
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -84,7 +84,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
return SearchBar(
|
||||
controller: controller,
|
||||
padding: WidgetStateProperty.all<EdgeInsetsGeometry>(
|
||||
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
|
||||
const EdgeInsets.only(
|
||||
top: 6.0,
|
||||
bottom: 6.0,
|
||||
@ -96,10 +96,10 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
controller.openView();
|
||||
_onSearchChanged('');
|
||||
},
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
const Color.fromARGB(255, 30, 30, 30)),
|
||||
hintText: 'Search contacts',
|
||||
hintStyle: WidgetStateProperty.all(
|
||||
hintStyle: MaterialStateProperty.all(
|
||||
const TextStyle(color: Colors.grey, fontSize: 16.0),
|
||||
),
|
||||
leading: const Icon(
|
||||
@ -107,7 +107,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
color: Colors.grey,
|
||||
size: 24.0,
|
||||
),
|
||||
shape: WidgetStateProperty.all<RoundedRectangleBorder>(
|
||||
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user