-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.dart
117 lines (112 loc) · 4.11 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import 'package:flutter/material.dart';
import 'package:flutter_truecaller/flutter_truecaller.dart';
import 'verify_non_truecaller.dart';
void main() => runApp(
MaterialApp(
home: MyApp(),
debugShowCheckedModeBanner: false,
),
);
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _result = '';
final FlutterTruecaller caller = FlutterTruecaller();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Truecaller Plugin Example'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
OutlineButton(
onPressed: () async {
String result = await caller.initializeSDK(
buttonColor: Colors.black,
buttonTextColor: Colors.white,
loginTextPrefix:
FlutterTruecallerScope.LOGIN_TEXT_PREFIX_TO_CONTINUE,
loginTextSuffix: FlutterTruecallerScope
.LOGIN_TEXT_SUFFIX_PLEASE_VERIFY_MOBILE_NO,
ctaTextPrefix:
FlutterTruecallerScope.CTA_TEXT_PREFIX_CONTINUE_WITH,
buttonShapeOptions:
FlutterTruecallerScope.BUTTON_SHAPE_RECTANGLE,
privacyPolicyUrl: "https://www.truecaller.com",
termsOfServiceUrl: "https://www.truecaller.com",
footerType: FlutterTruecallerScope.FOOTER_TYPE_LATER,
consentTitleOptions:
FlutterTruecallerScope.SDK_CONSENT_TITLE_VERIFY,
sdkOptions: FlutterTruecallerScope.SDK_OPTION_WITH_OTP,
);
setState(() {
_result = result;
});
},
child: Text('Initialize SDK'),
),
OutlineButton(
onPressed: () async {
bool isUsable = await caller.isUsable;
setState(() {
_result = isUsable ? "Usable" : "Not usable";
});
},
child: Text('Is usable?'),
),
OutlineButton(
onPressed: () async {
String result =
await caller.setLocale(FlutterTruecallerLocales.Hindi);
setState(() {
_result = result;
});
},
child: Text('Change Locale'),
),
OutlineButton(
onPressed: () async {
await caller.getProfile();
FlutterTruecaller.manualVerificationRequired
.listen((required) {
if (required)
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => Verify(),
),
);
});
},
child: Text('Get Profile'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(_result ?? 'ERROR'),
),
StreamBuilder<String>(
stream: FlutterTruecaller.callback,
builder: (context, snapshot) => Text(snapshot.data ?? ''),
),
StreamBuilder<FlutterTruecallerException>(
stream: FlutterTruecaller.errors,
builder: (context, snapshot) =>
Text(snapshot.hasData ? snapshot.data.errorMessage : ''),
),
StreamBuilder<TruecallerProfile>(
stream: FlutterTruecaller.trueProfile,
builder: (context, snapshot) =>
Text(snapshot.hasData ? snapshot.data.firstName : ''),
),
],
),
),
),
);
}
}