Login with Truecaller

  1. Add plugin in pubspec.yml
  2. import package where you want to add true caller login
  3. create true caller developer account, and your project
  4. <meta-data

android:name="com.truecaller.android.sdk.PartnerKey" android:value="uDIKT4db642a7606d43b0995b2a3c6a63756a"/>

5.Add above code in Manifest.xml file

6.Rename FlutterActivity to FlutterFragmentActivity in MainActivity.kt file

7.give user permissions in Manifest.xml file

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>

8.main code

TruecallerSdk.initializeSDK(sdkOptions: TruecallerSdkScope.SDK_OPTION_WITH_OTP,
  consentMode:TruecallerSdkScope.CONSENT_MODE_POPUP,
  footerType:TruecallerSdkScope.FOOTER_TYPE_ANOTHER_METHOD,

);
TruecallerSdk.isUsable.then((isUsable) {
  if (!isUsable) {
    TruecallerSdk.getProfile;

    StreamSubscription streamSubscription = TruecallerSdk.streamCallbackData.listen((truecallerSdkCallback) {
      switch (truecallerSdkCallback.result) {
        case TruecallerSdkCallbackResult.success:
        //If Truecaller user and has Truecaller app on his device, you'd directly get the Profile
          String firstName = truecallerSdkCallback.profile!.firstName;
          String? lastName = truecallerSdkCallback.profile!.lastName;
          String phNo = truecallerSdkCallback.profile!.phoneNumber;
          debugPrint("Kane:$firstName ...$lastName .. $phNo");
      gettruecaller(first_name, last_name, mobile_number);
          // Navigator.push(context,
          // MaterialPageRoute(builder: (context)=>Registration())
          // );
          break;
        case TruecallerSdkCallbackResult.failure:
          int errorCode = truecallerSdkCallback.error!.code;
          break;
        case TruecallerSdkCallbackResult.verification:
        //If the callback comes here, it indicates that user has to be manually verified, so follow step 4
        //You'd receive nullable error which can be used to determine user action that led to verification
          int? errorCode = truecallerSdkCallback.error?.code;
          print("Manual Verification Required!");
          break;
        default:
          print("Invalid result");
      }
    });


  } else {
    // final snackBar = SnackBar(content: Text("Not Usable"));
    // ScaffoldMessenger.of(context).showSnackBar(snackBar);
    // print("***Not usable***");
  }
});
gettruecaller(String first_name, String last_name, String mobile_number){
  truecallerapi(first_name, last_name, mobile_number).then((data) => {
    if(data != null){
      if(data.error == 1){
        Navigator.push(context, 
        MaterialPageRoute(builder: (context)=>Registration())
        )
      }else{
        _showToast(data.message),
      },
      debugPrint("aa${data.error}.... ${data.message}")
    }
  });





Sign In or Register to comment.