callService static method
Implementation
static String callService(String projectName) {
return '''
import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:$projectName/core/services/feature_service.dart';
/// Helper to open the phone dialer or start a call.
///
/// Usage:
/// await CallService.callNumber("+919876543210");
/// await CallService.callNumber("9876543210");
class CallService {
static Future<void> callNumber(String phoneNumber) async {
if (!FeatureService.isCallEnabled) {
throw Exception('Call feature is disabled. Enable it in settings.');
}
// Normalize the phone number: remove spaces, dashes, parentheses
String normalized = phoneNumber.replaceAll(RegExp(r'[\\s\\-\\(\\)]'), '');
// If number doesn't start with +, add +91 (India default)
if (!normalized.startsWith('+')) {
// If it starts with 0, remove it and add +91
if (normalized.startsWith('0')) {
normalized = '+91\${normalized.substring(1)}';
} else {
normalized = '+91\$normalized';
}
}
final uri = Uri.parse('tel:\$normalized');
try {
await launchUrl(
uri,
mode: LaunchMode.externalApplication,
);
} catch (e) {
if (kDebugMode) {
debugPrint('Dialer launch failed: \$e');
}
throw Exception('Unable to open dialer');
}
}
}
''';
}