shareid_onboarding_sdk 1.0.2 shareid_onboarding_sdk: ^1.0.2 copied to clipboard
The ShareID SDKs are built in design to offer the best user experience. We leverage artificial intelligence during the acquisition phase to enable a frictionless user experience. The modular design en [...]
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:fluttertoast/fluttertoast.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;
});
result = ResultService("", "");
ServiceRequest onBoardingService = ServiceRequest(
audience: "onboarding_service",
businessIdentifier: "Business Request Id",
businessSecret: "Business Request Token",
callbackUrl: "Callback Url");
final dio = Dio();
final client = ShareProvider(dio);
client.getBusinessToken(onBoardingService).then((it) async {
tokens.add(it);
onBoardingServiceToken = it.servicePayload!.token!;
print("Token $onBoardingServiceToken");
_shareid
.signUp(
onBoardingServiceToken, "Callback Url", "External id is optional")
.then((value) {
setState(() {
result.getCode(value ?? "");
result.getMessage(value ?? "");
Fluttertoast.showToast(msg: result.getMessage(value ?? ""));
});
});
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,
),
],
),
)
],
),
),
),
);
}
}