dynatrace_flutter_plugin_dio 3.305.2 copy "dynatrace_flutter_plugin_dio: ^3.305.2" to clipboard
dynatrace_flutter_plugin_dio: ^3.305.2 copied to clipboard

An extension of the Dynatrace Flutter Plugin which allows support for instrumentation of the Dio package.

example/main.dart

import 'package:dio/dio.dart';
import 'package:dynatrace_flutter_plugin_dio/dynatrace_flutter_plugin_dio.dart';
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';
import 'package:flutter/material.dart';

main() {
  // See https://pub.dev/packages/dynatrace_flutter_plugin#quick-setup
  // for how to configure our plugin properly!
  Dynatrace().start(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Dynatrace Dio Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _dioRequestWithAction() async {
    final dio = Dio();
    dio.instrument();

    var url = 'https://dynatrace.com';
    DynatraceRootAction dioAction =
        Dynatrace().enterAction('Dio Action - $url');

    try {
      await dio.get(url);
    } catch (error) {
      // insert error handling here
    } finally {
      dioAction.leaveAction();
    }
  }

  void _dioRequestWithoutAction() async {
    final dio = Dio();
    dio.instrument();

    try {
      await dio.get('https://dynatrace.com');
    } catch (error) {
      // insert error handling here
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Dio Request Examples',
            ),
            FloatingActionButton(
              onPressed: _dioRequestWithAction,
              tooltip: 'Dio Request With Action',
              child: const Icon(Icons.add),
            ),
            FloatingActionButton(
              onPressed: _dioRequestWithoutAction,
              tooltip: 'Dio Request Without Action',
              child: const Icon(Icons.check),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
150
points
6.08k
downloads

Publisher

verified publisherdynatrace.com

Weekly Downloads

An extension of the Dynatrace Flutter Plugin which allows support for instrumentation of the Dio package.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

dio, dynatrace_flutter_plugin, flutter

More

Packages that depend on dynatrace_flutter_plugin_dio