datadome_flutter_dio 1.1.1 datadome_flutter_dio: ^1.1.1 copied to clipboard
A DataDome integration for Flutter - Dio Integration
import 'package:datadome_flutter_dio/datadome_logger.dart';
import 'package:datadome_flutter_dio/tracking/gesture_detection.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:datadome_flutter_dio/datadome_interceptor.dart';
import 'package:dio/dio.dart';
import 'package:datadome_flutter_dio_example/datadome_secrets.dart';
void main() {
runApp(MaterialApp(
home: MyApp()
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
}
void displayCaptcha(Widget view) {
showGeneralDialog(
context: context,
barrierDismissible: false,
pageBuilder: (context, __, ___) {
return view;
},
);
}
void dismissCaptcha() {
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: GestureDetection(
child: Scaffold(
appBar: AppBar(
title: const Text('DataDome example app'),
),
body:
Center(
child: MaterialButton(onPressed: () async {
//make request
var dio = Dio();
DataDomeLogger.setLogLevel(LogLevel.info);
DataDomeInterceptor dataDomeInterceptor = DataDomeInterceptor.withCallback(datadome_client_key, dio, (widget) { displayCaptcha(widget); }, () { dismissCaptcha(); });
dio.interceptors.add(dataDomeInterceptor);
try {
var response = await dio.get(test_url, options: Options(headers: {'User-Agent': 'BLOCKUA', 'Accept': 'application/json'}));
print(response);
} catch (e) {
print(e);
}
},
child: Text(
'Make Request'
),
),
),
),
)
);
}
}