dynatrace_flutter_plugin_dio 3.289.1 copy "dynatrace_flutter_plugin_dio: ^3.289.1" to clipboard
dynatrace_flutter_plugin_dio: ^3.289.1 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-web.flutter-io.cn/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
130
pub points
85%
popularity

Publisher

verified publisherdynatrace.com

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