shareid_onboarding_sdk 2.0.2 shareid_onboarding_sdk: ^2.0.2 copied to clipboard
The ShareID SDKs are built in design to offer the best user experience.
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:shareid_onboarding_sdk/shareid_onboarding_sdk.dart';
import 'models/service_request.dart';
import 'models/service_response.dart';
import 'models/service_result.dart';
import 'providers/share_provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _shareid = ShareidOnboarding();
Color primaryColor = const Color(0xff2A4DC6);
bool isLoading = false;
@override
void initState() {
super.initState();
}
List<ServiceResponse> tokens = [];
String onBoardingServiceToken = "";
late ResultService result;
void getTokens() {
setState(() {
isLoading = true;
});
ServiceRequest onBoardingService = ServiceRequest(
//true or false for Advanced Verification,
advancedVerification: false,
businessHash: "Your Business Hash",
apiKey: "Your API Key",
//Supported methods are doc, face you can put doc only or face only or both
methods: ["doc", "face"],
//add custom data here if needed
customData: {},
callback: "Your Callback URL",
);
final dio = Dio();
final client = ShareProvider(dio);
client.getBusinessToken(onBoardingService).then((it) async {
tokens.add(it);
onBoardingServiceToken = it.token!;
_shareid.signUp("Server Url", onBoardingServiceToken).then((value) {
setState(() {
Map<String, dynamic> valueMap = json.decode(value!);
result = ResultService.fromJson(valueMap);
});
});
setState(() {
isLoading = false;
});
}).catchError((Object obj) {
setState(() {
isLoading = false;
});
switch (obj.runtimeType) {
case DioError:
final res = (obj as DioError).response;
if (res != null) {
} else {}
break;
default:
print("Got error $obj");
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
margin: const EdgeInsets.only(top: 140),
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 20),
child: Image.asset("assets/images/logo_share.png"),
),
isLoading
? CircularProgressIndicator(
color: primaryColor,
)
: const SizedBox.shrink(),
Container(
margin: const EdgeInsets.only(bottom: 56),
child: Column(
children: [
ElevatedButton(
onPressed: () {
if (!isLoading) getTokens();
},
style: ElevatedButton.styleFrom(
side: BorderSide(width: 2.0, color: primaryColor),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 15),
child: Center(
child: Text(
'S\'inscrire',
style: TextStyle(color: primaryColor),
),
),
),
),
const SizedBox(
height: 10,
),
],
),
)
],
),
),
),
);
}
}