Skip to content

Commit

Permalink
updated examples to incorporate non-tc flow
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhral-kumar committed Aug 24, 2020
1 parent d9518b7 commit 5f5f6d9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
39 changes: 25 additions & 14 deletions example/lib/customization/main_customization_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:truecaller_sdk/truecaller_sdk.dart';
import 'package:truecaller_sdk_example/non_tc_screen.dart';

import 'config_options.dart';
import 'result_screen.dart';
Expand Down Expand Up @@ -443,6 +444,7 @@ class _HomePageState extends State<HomePage> {
selectedConsentMode = TruecallerSdkScope.CONSENT_MODE_FULLSCREEN;
}
TruecallerSdk.initializeSDK(
sdkOptions: TruecallerSdkScope.SDK_OPTION_WITH_OTP,
consentMode: selectedConsentMode,
consentTitleOptions:
TitleOption.getTitleOptions().indexWhere((title) => title.name == selectedTitle.name),
Expand Down Expand Up @@ -476,21 +478,27 @@ class _HomePageState extends State<HomePage> {
void createStreamBuilder() {
streamSubscription = TruecallerSdk.getProfileStreamData.listen((truecallerUserCallback) {
switch (truecallerUserCallback.result) {
case TruecallerUserCallbackResult.success:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ResultScreen(truecallerUserCallback.profile.firstName, 1),
));
case TruecallerSdkCallbackResult.success:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ResultScreen(truecallerUserCallback.profile.firstName, 1),
));
break;
case TruecallerUserCallbackResult.failure:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
ResultScreen("Error code : ${truecallerUserCallback.error.code}", -1),
));
case TruecallerSdkCallbackResult.failure:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ResultScreen("Error code : ${truecallerUserCallback.error.code}", -1),
));
break;
case TruecallerUserCallbackResult.verification:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ResultScreen("Verification Required!!", 0),
));
case TruecallerSdkCallbackResult.verification:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NonTcVerification(),
));
break;
default:
print("Invalid result");
Expand All @@ -500,9 +508,12 @@ class _HomePageState extends State<HomePage> {

@override
void dispose() {
super.dispose();
privacyPolicyController.dispose();
termsOfServiceController.dispose();
localeController.dispose();
if (streamSubscription != null) {
streamSubscription.cancel();
}
super.dispose();
}
}
30 changes: 24 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:truecaller_sdk/truecaller_sdk.dart';
import 'package:truecaller_sdk_example/non_tc_screen.dart';

void main() {
runApp(MyApp());
Expand All @@ -25,7 +26,7 @@ class _MyAppState extends State<MyApp> {
children: <Widget>[
MaterialButton(
onPressed: () {
TruecallerSdk.initializeSDK();
TruecallerSdk.initializeSDK(sdkOptions: TruecallerSdkScope.SDK_OPTION_WITH_OTP);
TruecallerSdk.isUsable.then((isUsable) {
isUsable ? TruecallerSdk.getProfile : print("***Not usable***");
});
Expand All @@ -40,18 +41,35 @@ class _MyAppState extends State<MyApp> {
color: Colors.transparent,
height: 20.0,
),
StreamBuilder<TruecallerUserCallback>(
StreamBuilder<TruecallerSdkCallback>(
stream: TruecallerSdk.getProfileStreamData,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data.result) {
case TruecallerUserCallbackResult.success:
case TruecallerSdkCallbackResult.success:
return Text(
"Hi, ${snapshot.data.profile.firstName} ${snapshot.data.profile.lastName}");
case TruecallerUserCallbackResult.failure:
case TruecallerSdkCallbackResult.failure:
return Text("Oops!! Error type ${snapshot.data.error.code}");
case TruecallerUserCallbackResult.verification:
return Text("Verification Required");
case TruecallerSdkCallbackResult.verification:
return Column(
children: [
Text("Verification Required"),
MaterialButton(
color: Colors.green,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NonTcVerification()));
},
child: Text(
"Do manual verification",
style: TextStyle(color: Colors.white),
),
)
],
);
default:
return Text("Invalid result");
}
Expand Down

0 comments on commit 5f5f6d9

Please sign in to comment.