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