shareid_sdk_flutter 2.0.0 shareid_sdk_flutter: ^2.0.0 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:fluttertoast/fluttertoast.dart';
import 'package:shareid_sdk_flutter/shareid_sdk_flutter.dart';
import 'models/auth_request.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 = ShareidSdkFlutter();
Color primaryColor = const Color(0xff2A4DC6);
bool isLoading = false;
String uuid = "";
@override
void initState() {
super.initState();
}
List<ServiceResponse> tokens = [];
String onBoardingServiceToken = "";
late ResultService result;
void getOnboardingToken() {
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.getOnboardingToken(onBoardingService).then((it) async {
tokens.add(it);
onBoardingServiceToken = it.token!;
_shareid.onboarding("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");
}
});
}
void getAuthenticateToken() {
setState(() {
isLoading = true;
});
AuthServiceRequest authenticateService = AuthServiceRequest(
businessHash: "Your Business Hash",
apiKey: "Your API Key",
applicantId: "Your Applicant ID",
callback: "Your Callback URL",
);
final dio = Dio();
final client = ShareProvider(dio);
client.getAuthenticateToken(authenticateService).then((it) async {
tokens.add(it);
onBoardingServiceToken = it.token!;
_shareid.authenticate("Server Url", onBoardingServiceToken).then((value) {
setState(() {
Map<String, dynamic> valueMap = json.decode(value!);
result = ResultService.fromJson(valueMap);
Fluttertoast.showToast(msg: result.message!);
});
});
setState(() {
isLoading = false;
});
}).catchError((Object obj) {
setState(() {
isLoading = false;
});
switch (obj.runtimeType) {
case DioError:
final res = (obj as DioError).response;
if (res != null) {
print("Got error ${res.statusCode} -> ${res.statusMessage}");
} else {}
break;
default:
print("Got error $obj");
}
});
}
Future<void> displayDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Your UUID'),
content: TextField(
onChanged: (value) {
setState(() {
uuid = value;
});
},
//controller: _textFieldController,
decoration: const InputDecoration(hintText: "Put your uuid"),
),
actions: <Widget>[
MaterialButton(
color: primaryColor,
textColor: Colors.white,
child: const Text('Submit'),
onPressed: () {
setState(() {
getAuthenticateToken();
Navigator.pop(context);
});
},
),
],
);
});
}
@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("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) displayDialog(context);
},
style: ElevatedButton.styleFrom(
side: BorderSide(width: 2.0, color: primaryColor),
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 15),
child: const Center(
child: Text(
'Se connecter',
style: TextStyle(color: Colors.white),
),
),
),
),
const SizedBox(
height: 10,
),
ElevatedButton(
onPressed: () {
if (!isLoading) getOnboardingToken();
},
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),
),
),
),
)
],
),
)
],
),
),
),
);
}
}