feat: add contact during call if contact is unknown
This commit is contained in:
parent
81187f4384
commit
ce7a5b10b0
@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:dialer/services/call_service.dart';
|
||||
import 'package:dialer/services/obfuscate_service.dart';
|
||||
import 'package:dialer/widgets/username_color_generator.dart';
|
||||
@ -35,6 +36,8 @@ class _CallPageState extends State<CallPage> {
|
||||
StreamSubscription<String>? _callStateSubscription;
|
||||
StreamSubscription<Map<String, dynamic>>? _audioStateSubscription;
|
||||
|
||||
bool get isNumberUnknown => widget.displayName == widget.phoneNumber;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -198,6 +201,23 @@ class _CallPageState extends State<CallPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _addContact() async {
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
final newContact = Contact()..phones = [Phone(widget.phoneNumber)];
|
||||
final updatedContact =
|
||||
await FlutterContacts.openExternalInsert(newContact);
|
||||
if (updatedContact != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Contact added successfully!')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Permission denied for contacts')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double avatarRadius = isKeypadVisible ? 45.0 : 45.0;
|
||||
@ -416,24 +436,25 @@ class _CallPageState extends State<CallPage> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.person_add,
|
||||
color: Colors.white,
|
||||
size: 32,
|
||||
if (isNumberUnknown)
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: _addContact,
|
||||
icon: const Icon(
|
||||
Icons.person_add,
|
||||
color: Colors.white,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
'Add Contact',
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Text(
|
||||
'Add Contact',
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
Loading…
Reference in New Issue
Block a user