composition-page #13
@ -1,6 +1,8 @@
|
|||||||
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 '../../widgets/contact_service.dart';
|
||||||
|
import '../contacts/widgets/add_contact_button.dart';
|
||||||
|
|
||||||
class CompositionPage extends StatefulWidget {
|
class CompositionPage extends StatefulWidget {
|
||||||
const CompositionPage({super.key});
|
const CompositionPage({super.key});
|
||||||
@ -63,9 +65,24 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholder function for adding contact
|
// Function to call a contact's number
|
||||||
void addContact(String number) {
|
void _launchPhoneDialer(String phoneNumber) async {
|
||||||
// This function is empty for now
|
final uri = Uri(scheme: 'tel', path: phoneNumber);
|
||||||
|
if (await canLaunchUrl(uri)) {
|
||||||
|
await launchUrl(uri);
|
||||||
|
} else {
|
||||||
|
debugPrint('Could not launch $phoneNumber');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to send an SMS to a contact's number
|
||||||
|
void _launchSms(String phoneNumber) async {
|
||||||
|
final uri = Uri(scheme: 'sms', path: phoneNumber);
|
||||||
|
if (await canLaunchUrl(uri)) {
|
||||||
|
await launchUrl(uri);
|
||||||
|
} else {
|
||||||
|
debugPrint('Could not send SMS to $phoneNumber');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -90,19 +107,20 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
children: _filteredContacts.isNotEmpty
|
children: _filteredContacts.isNotEmpty
|
||||||
? _filteredContacts.map((contact) {
|
? _filteredContacts.map((contact) {
|
||||||
|
final phoneNumber = contact.phones.isNotEmpty
|
||||||
|
? contact.phones.first.number
|
||||||
|
: 'No phone number';
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
contact.displayName,
|
contact.displayName,
|
||||||
style:
|
style:
|
||||||
const TextStyle(color: Colors.white),
|
const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
subtitle: contact.phones.isNotEmpty
|
subtitle: Text(
|
||||||
? Text(
|
phoneNumber,
|
||||||
contact.phones.first.number,
|
style:
|
||||||
style: const TextStyle(
|
const TextStyle(color: Colors.grey),
|
||||||
color: Colors.grey),
|
),
|
||||||
)
|
|
||||||
: null,
|
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@ -112,18 +130,16 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
color: Colors.green[300],
|
color: Colors.green[300],
|
||||||
size: 20),
|
size: 20),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
print(
|
_launchPhoneDialer(phoneNumber);
|
||||||
'Calling ${contact.displayName}');
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Text button
|
// Message 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: () {
|
||||||
print(
|
_launchSms(phoneNumber);
|
||||||
'Texting ${contact.displayName}');
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -228,20 +244,19 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Add Contact Button with empty function call
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 20.0),
|
|
||||||
child: FloatingActionButton(
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
onPressed: () {
|
|
||||||
addContact(dialedNumber);
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.person_add, color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Add Contact Button
|
||||||
|
Positioned(
|
||||||
|
bottom: 20.0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Center(
|
||||||
|
child: AddContactButton(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// Top Row with Back Arrow
|
// Top Row with Back Arrow
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 40.0,
|
top: 40.0,
|
||||||
|
@ -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