feat: give parameters to callPage to avoid fetching when possible
This commit is contained in:
parent
b11c62debc
commit
63e5632f9a
@ -267,8 +267,12 @@ class _ContactModalState extends State<ContactModal> {
|
||||
),
|
||||
onTap: () async {
|
||||
if (widget.contact.phones.isNotEmpty) {
|
||||
await _callService.makeGsmCall(context,
|
||||
phoneNumber: phoneNumber);
|
||||
await _callService.makeGsmCall(
|
||||
context,
|
||||
phoneNumber: phoneNumber,
|
||||
displayName: widget.contact.displayName,
|
||||
thumbnail: widget.contact.thumbnail,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -425,7 +425,12 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
icon: const Icon(Icons.phone, color: Colors.green),
|
||||
onPressed: () async {
|
||||
if (contact.phones.isNotEmpty) {
|
||||
_callService.makeGsmCall(context, phoneNumber: contact.phones.first.number);
|
||||
await _callService.makeGsmCall(
|
||||
context,
|
||||
phoneNumber: contact.phones.first.number,
|
||||
displayName: contact.displayName,
|
||||
thumbnail: contact.thumbnail,
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
|
@ -1,16 +1,17 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../features/call/call_page.dart';
|
||||
import '../features/call/incoming_call_page.dart';
|
||||
import '../services/contact_service.dart'; // Import your ContactService
|
||||
import '../services/contact_service.dart';
|
||||
|
||||
class CallService {
|
||||
static const MethodChannel _channel = MethodChannel('call_service');
|
||||
static String? currentPhoneNumber;
|
||||
static String? currentDisplayName; // Store display name
|
||||
static Uint8List? currentThumbnail; // Store thumbnail
|
||||
static String? currentDisplayName;
|
||||
static Uint8List? currentThumbnail;
|
||||
static bool _isCallPageVisible = false;
|
||||
final ContactService _contactService = ContactService(); // Instantiate ContactService
|
||||
final ContactService _contactService = ContactService();
|
||||
|
||||
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
@ -28,7 +29,6 @@ class CallService {
|
||||
final phoneNumber = call.arguments["callId"] as String;
|
||||
final state = call.arguments["state"] as String;
|
||||
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
||||
// Fetch contact info using ContactService if not already set
|
||||
await _fetchContactInfo(currentPhoneNumber!);
|
||||
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
||||
if (state == "ringing") {
|
||||
@ -61,12 +61,12 @@ class CallService {
|
||||
}
|
||||
|
||||
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||
if (currentDisplayName != null && currentThumbnail != null) return; // Already set
|
||||
try {
|
||||
final contacts = await _contactService.fetchContacts(); // Use ContactService
|
||||
final contacts = await _contactService.fetchContacts();
|
||||
final normalizedPhoneNumber = _normalizePhoneNumber(phoneNumber);
|
||||
for (var contact in contacts) {
|
||||
for (var phone in contact.phones) {
|
||||
if (_normalizePhoneNumber(phone.number) == _normalizePhoneNumber(phoneNumber)) {
|
||||
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
||||
currentDisplayName = contact.displayName;
|
||||
currentThumbnail = contact.thumbnail;
|
||||
return;
|
||||
@ -74,8 +74,8 @@ class CallService {
|
||||
}
|
||||
}
|
||||
// If no match found, use phone number as fallback
|
||||
currentDisplayName ??= phoneNumber;
|
||||
currentThumbnail ??= null;
|
||||
currentDisplayName = phoneNumber;
|
||||
currentThumbnail = null;
|
||||
} catch (e) {
|
||||
print('CallService: Error fetching contact info: $e');
|
||||
currentDisplayName = phoneNumber;
|
||||
@ -151,8 +151,12 @@ class CallService {
|
||||
}) async {
|
||||
try {
|
||||
currentPhoneNumber = phoneNumber;
|
||||
currentDisplayName = displayName ?? phoneNumber; // Use provided or fetch later
|
||||
currentThumbnail = thumbnail; // Use provided or fetch later
|
||||
// Use provided displayName and thumbnail if available, otherwise fetch
|
||||
currentDisplayName = displayName ?? phoneNumber;
|
||||
currentThumbnail = thumbnail;
|
||||
if (displayName == null || thumbnail == null) {
|
||||
await _fetchContactInfo(phoneNumber);
|
||||
}
|
||||
print('CallService: Making GSM call to $phoneNumber');
|
||||
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
||||
print('CallService: makeGsmCall result: $result');
|
||||
@ -162,9 +166,7 @@ class CallService {
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Fetch contact info if not provided
|
||||
await _fetchContactInfo(phoneNumber);
|
||||
_navigateToCallPage(context); // Navigate immediately after call initiation
|
||||
_navigateToCallPage(context);
|
||||
} catch (e) {
|
||||
print("CallService: Error making call: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
Loading…
Reference in New Issue
Block a user