Skip to main content

Pitel VoIP Flutter SDK

flutter_pitel_voip_v2 provides Pitel SIP calling for Flutter apps on Android and iOS. Partners install the prebuilt SDK from flutter-pitel-voip-sdk-v2; this repository is used to maintain the SDK source. This README is the primary partner integration guide.

IMPORTANT

Incoming iOS VoIP push must be tested on a physical iPhone. The iOS Simulator cannot provide a valid PushKit device token or receive VoIP pushes. Apple VoIP Services Certificates (.p12) expire annually. Renew the certificate and update it in the Pitel Portal before it expires.

Requirements​

  • Flutter: the example toolchain is 3.44.0; the source checkout pins it in .fvmrc, which may not be included in a binary distribution. Dart compatibility follows pubspec.yaml (^3.10.4 currently).
  • Android: API 24+, arm64-v8a; the example uses Java 17 and its configured Gradle/Android toolchain.
  • iOS: iOS 14+, device arm64. The current binary does not include iOS Simulator architecture.
  • Firebase: Host app configures firebase_core and firebase_messaging for the push/token flows it uses.

📚 Documentation Index​

GuideDescription
🚀 Quick start guideInstall from the SDK repository and configure Firebase, Portal, Android, iOS, and Dart.
📱 Example instructionsRun the example from this source repository or from a binary distribution.
🍎 iOS VoIP Push & CallKit setupApple certificates, APNs key, Firebase and Xcode configuration; includes screenshots.
🤖 Android push notification setupFirebase setup, custom FCM service and testing steps; includes screenshots.
🌐 Web Portal guideConfigure app identifiers and upload Portal credentials; includes screenshots.
🛡️ Android Full-Screen Intent guideFSI configuration and current policy references.
🧩 Public Flutter APIMethods, events and platform differences.
🎨 Native UI customizationCustomize call screen colors, labels and controls.
📖 Call disconnect and error codesSIP status codes and disconnect explanations.
❓ FAQ and test checklistPartner acceptance checks and common questions.
🛠️ Troubleshooting guideResolve package, build, push, registration and audio problems.

1. Prepare​

Prepare SSH access to the private distribution repository, an existing release tag, SIP credentials (including proxy/port), and Firebase/Portal credentials. Check GitHub access with ssh -T git@github.com.

2. Install the package​

In the host app pubspec.yaml, add the released tag:

dependencies:
flutter_pitel_voip_v2:
git:
url: git@github.com:voip-sdk/flutter-pitel-voip-sdk-v2.git
ref: <existing-release-tag>
firebase_core: ^3.10.1
firebase_messaging: ^15.2.1

Replace <existing-release-tag> with a released tag and run flutter pub get. The Firebase constraints match the example; keep compatible versions if your app already uses Firebase. Import:

import 'package:flutter_pitel_voip_v2/flutter_pitel_voip_v2.dart';

Flutter registers the plugin automatically. If resolution fails, check repository access, the tag and package name.

3. Firebase and Pitel Portal​

Match Firebase, Portal and PitelSettings.appId to the Android applicationId or iOS bundle ID. Android namespace may differ from applicationId.

File / valueWhere it belongsKeep private?
google-services.jsonHost Android app at android/app/google-services.json; register the Android applicationId in FirebaseApp config; do not commit if your policy treats it as sensitive
GoogleService-Info.plistHost iOS app, added to the Runner/app target in XcodeApp config; do not commit if your policy treats it as sensitive
Firebase service-account JSONPitel Portal/backend credential configuration, not bundled into the mobile appYes; never put in app assets or source control
APNs .p8, Key ID, Team IDFirebase project Apple push configurationYes for .p8; keep private
VoIP certificate .p12Pitel Portal iOS app configurationYes; protect its password and private key

Follow the Portal walkthrough to upload credentials. Private service-account, APNs and certificate keys belong in Firebase/Portal, never in app assets or source control.

4. Android setup​

Merge the following into your host app:

  1. Place your Firebase app’s google-services.json in android/app/.
  2. Set minSdk = 24 and Java/Kotlin target 17 in android/app/build.gradle.kts.
  3. Apply Google Services and add Firebase Messaging for the native service.
  4. Create CustomMessagingService.kt in your app’s package. It routes Pitel pushes to PitelClient and saves refreshed tokens.
  5. In AndroidManifest.xml, register the custom service and remove the Pitel and FlutterFire default messaging services. Check the Merged Manifest has one MESSAGING_EVENT service.
  6. For fullscreen incoming calls, declare USE_FULL_SCREEN_INTENT and follow the FSI guide. Use IncomingCallMode.notification for notification presentation.

Follow the Android push guide for the Kotlin DSL and service code. The service's Kotlin package must match its manifest class name; applicationId must match Firebase, Portal and PitelSettings.appId. The AAR supplies SDK permissions and consumer R8 rules; no extra SDK keep rules are required. Non-Pitel messages remain the host app’s responsibility.

5. iOS setup​

  1. Set iOS 14+ and merge the example’s use_frameworks! / post_install settings into ios/Podfile.
  2. Run flutter pub get, then cd ios && pod install. Open Runner.xcworkspace.
  3. Add your GoogleService-Info.plist to the Runner target; verify Target Membership.
  4. Enable Push Notifications and the calling-related Background Modes. Add NSMicrophoneUsageDescription to ios/Runner/Info.plist.
  5. Keep the host’s generated Flutter plugin registration in AppDelegate.swift, including its implicit-engine pattern if present. The plugin manages PushKit/CallKit.

Use the iOS guide for the Podfile, AppDelegate and Apple/Firebase walkthrough. Keep your app’s bundle ID and signing configuration. Camera, local-network and Background Processing settings depend on the host app’s own features.

6. SDK usage​

Use PitelVoipClient.instance in your app's state/controller. Put imports at the top of the Dart file and usage snippets inside async methods. The complete example shows how to connect these steps to a Flutter app.

import 'package:flutter_pitel_voip_v2/flutter_pitel_voip_v2.dart';

final client = PitelVoipClient.instance;

Initialize Firebase and the client​

Initialize Firebase, obtain the initial FCM token, and pass initial/refreshed tokens to client.setFCMToken(). See the example's app entry point and Firebase/token setup.

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

await Firebase.initializeApp();
final fcmToken = await FirebaseMessaging.instance.getToken();
if (fcmToken != null) {
await client.setFCMToken(fcmToken);
}

Run after Flutter binding initialization. The example shows permission requests, token refresh and error handling.

Handle token setup failures separately so app startup and SDK listeners remain available; retry when appropriate. SIP registered and a completed setFCMToken() call do not prove push delivery. See Android token handling and iOS token roles.

Attach listeners before login​

Attach registration and call listeners before login or auto-login. Enable calling only after PitelRegistrationState.registered. See the example's initialization and call-event handling.

final registrationSubscription =
client.onRegistrationStateChanged.listen((state) {
// Enable calling when state == PitelRegistrationState.registered.
});
final callSubscription = client.events.listen((event) {
// Handle call events.
});

Keep these subscriptions in the owning state/controller and cancel them at teardown; see Clean up listeners.

Check permissions at startup, before outgoing calls, and on incoming events while the app is foregrounded. See the example's permission check and the permission notes.

Login​

Where: the user’s Login action, after validating the account fields. See the example's _login().

if (!await client.requestPermissions()) {
throw StateError('Calling permissions are required.');
}

await client.login(PitelSettings(
extension: 'YOUR_EXTENSION',
password: 'YOUR_SIP_PASSWORD',
domain: 'YOUR_SIP_DOMAIN',
proxy: 'sip:YOUR_PROXY_HOST:YOUR_PROXY_PORT',
port: 'YOUR_SIP_REGISTRAR_PORT',
displayName: 'YOUR_DISPLAY_NAME',
teamId: 'YOUR_APPLE_TEAM_ID',
appId: 'YOUR_BUNDLE_ID',
appMode: 'production', // 'dev' for Debug mode; 'production' for TestFlight / App Store
incomingCallMode: IncomingCallMode.fullscreen, // Android: fullscreen (requires FSI setup) or notification
userAgent: 'YOUR_USER_AGENT', // Optional, e.g. 'Pitel App' (default: 'Pitel VoIP Flutter')
));

Supply proxy and port for partner integration, even though the constructor allows an omitted proxy and defaults port to 50061.

SettingValue to provide
extension, passwordSIP credentials issued by Pitel/PBX
domainSIP registrar host; no https://
proxy, portAccount-issued proxy URI and registrar port; required for integration
displayNameName shown to the other caller
teamIdApple Developer Team ID; required by the current Dart API on both platforms
appIdAndroid applicationId or iOS bundle ID, matching Firebase/Portal
appMode'dev' (Debug mode) or 'production' (TestFlight / App Store); default is 'production'
incomingCallModeAndroid fullscreen (default) or notification; see the Android Full-Screen Intent guide
userAgentCustom User-Agent identifier cho SIP registration và PBX API (optional, default: 'Pitel VoIP Flutter'). Tự động loại bỏ dấu tiếng Việt, ký tự đặc biệt, giới hạn tối đa 30 ký tự.

On iOS, appMode controls the APNs environment:

  • 'dev': use during development / Debug mode (connects to Apple Sandbox APNs).
  • 'production': use when building/deploying to TestFlight or the App Store (connects to Apple Production APNs).

Android currently ignores this field for device registration and automatically uses dev when the host app is debuggable, otherwise production. For Android 14+ full-screen incoming call configuration and policies, see the Android Full-Screen Intent guide.

login() starts registration. Wait for the listener to report registered before showing SIP readiness.

Restore a saved session​

Where: startup, after attaching listeners and attempting token/permission setup. See the example's session restore.

final restored = await client.autoLogin();
if (!restored) {
// Show your manual login flow.
}

If startup permission was denied, explain the limitation and request it again from a foreground UI before calling. true means the saved login attempt started or the client was already registered; confirm readiness through the registration stream. The SDK stores login data in unencrypted SharedPreferences; do not access its private keys.

autoLogin() automatically restores any saved uiConfig; see UI customization.

Make a call​

Where: the user’s Call action, after SIP reports registered and call permissions are granted. Re-check permissions before every call. The example's _makeCall() shows permission handling and destination formatting.

await client.makeCall(
to: 'PHONE_NUMBER', // Extension (e.g., '101') or full SIP URI ('sip:phoneNumber@domain:port')
);

Handle failures in the host UI and prevent overlapping login/logout/call operations. In widgets, check mounted after asynchronous work before updating UI.

Logout​

Where: the user’s explicit Logout action. Do not run this immediately after makeCall() or automatically on screen disposal.

await client.logout();

Logout unregisters and clears SDK-saved login data.

Clean up listeners​

Cancel subscriptions when their owning screen/controller is disposed. The example's dispose() shows registration/call subscription cleanup; also cancel any Firebase token subscription owned by your host app. Keep listeners alive throughout the active session, and use logout only for an explicit sign-out action.

Incoming calls​

Android Pitel pushes go through the native FCM service; iOS VoIP pushes use PushKit/APNs. The SDK presents its native call UI.

FlutterFire callbacks only handle messages actually delivered to FlutterFire. They do not replace these native call routes. The example shows optional callback handling; the custom Android service does not forward non-Pitel messages to Dart automatically.

7. Verify the integration​

  • Package resolves from the intended demo-repo release tag; Android arm64 and iOS device builds succeed.
  • Login emits registered; outgoing calls connect with two-way audio.
  • Incoming calls work in foreground, background and on the lock screen on physical devices.
  • Permission denial, token refresh and logout behave correctly.
  • Test OS-terminated and user force-stopped states separately; wake-up after force-stop is not guaranteed.