datadome_flutter_dio 1.0.5 copy "datadome_flutter_dio: ^1.0.5" to clipboard
datadome_flutter_dio: ^1.0.5 copied to clipboard

outdated

A DataDome integration for Flutter - Dio Integration

example/lib/main.dart

import 'package:datadome_flutter_dio/datadome_logger.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:datadome_flutter_dio/datadome_interceptor.dart';

import 'package:dio/dio.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;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('DataDome example app'),
        ),
        body: Center(
          child: MaterialButton(onPressed: () async {
            //make request
            var dio = Dio();
            DataDomeLogger.setLogLevel(LogLevel.info);
            dio.interceptors.add(DataDomeInterceptor('test', dio, context));
            try {
              var response = await dio.get('https://datadome.co/wp-json', options: Options(headers: {'User-Agent': 'BLOCKUA'}));
              print(response);
            } catch (e) {
              print(e);
            }
          },
            child: Text(
                'Make Request'
            ),
          ),
        ),
      ),
    );
  }
}