dynatrace_flutter_plugin 1.205.0 copy "dynatrace_flutter_plugin: ^1.205.0" to clipboard
dynatrace_flutter_plugin: ^1.205.0 copied to clipboard

outdated

The Dynatrace Flutter plugin helps auto-instrument your Flutter app with Dynatrace OneAgent for Android and iOS. It also provides an API to add manual instrumentation.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

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

const String HOME_NAV = 'homeNav';
const String TEST_NAV = 'testNav';
main() {
  Dynatrace().start(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Dynatrace Test App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      onUnknownRoute: (settings) => MaterialPageRoute(
          builder: (context) => UndefinedView(
                name: settings.name,
              )),
      initialRoute: HOME_NAV,
      routes: {
        HOME_NAV: (context) => MyHomePage(),
        TEST_NAV: (context) => TestNav(),
      },
      navigatorObservers: [DynatraceNavigationObserver()],
      home: MyHomePage(),
    );
  }
}

class TestNav extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: FloatingActionButton(
          child: Icon(Icons.navigate_before),
          onPressed: () {
            Navigator.pushNamed(context, HOME_NAV);
          },
        ),
      ),
    );
  }
}

class UndefinedView extends StatelessWidget {
  final String name;
  const UndefinedView({Key key, this.name}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('No route defined here!'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, title}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var appBarText = new Text("Dynatrace Test App");
  static var _context;

  static const List<String> buttonOptions = [
    'Single Action',
    'Sub Action',
    'Web Action',
    'Report values',
    'Make Navigation',
    'Force errors',
    'Report crash',
    'Flush data',
    'Tag user',
    'End Session',
    'setGpsLocation: Hawaii',
    'Collection: Off',
    'Collection: Perf',
    'Collection: User',
    'Crash Opt-In: true',
    'Crash Opt-In: false',
    'getDataCollectionLevel',
    'isCrashReportingOptedIn',
  ];

  List<VoidCallback> actions = [
    _singleAction,
    _subAction,
    _webAction,
    _reportAll,
    _makeNavigation,
    _forceErrors,
    _reportCrash,
    _flushData,
    _tagUser,
    _endSession,
    _setGpsLocationHawaii,
    _collectionOff,
    _collectionPerformance,
    _collectionUserBehavior,
    _crashOptedInTrue,
    _crashOptedInFalse,
    () async {
      print('Data collection level:');
      print(await _getCollectionLevel());
    },
    () async {
      print('Crash reporting enabled:');
      print(await _getCrashReportingOptIn());
    }
  ];

  @override
  Widget build(BuildContext context) {
    _context = context;

    final ScrollController sController = ScrollController();
    return Scaffold(
      appBar: AppBar(
        title: appBarText,
        automaticallyImplyLeading: false,
      ),
      body: Scrollbar(
        controller: sController,
        isAlwaysShown: true,
        child: SingleChildScrollView(
          controller: sController,
          padding: const EdgeInsets.all(20.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                for (int i = 0; i < buttonOptions.length; i++)
                  Container(
                    width: 280.0,
                    height: 45.0,
                    padding: const EdgeInsets.all(8.0),
                    child: RaisedButton(
                      textColor: Colors.white,
                      color: Colors.blue,
                      onPressed: actions[i],
                      child: Text(buttonOptions[i]),
                    ),
                  ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  static void _makeNavigation() {
    Navigator.pushNamed(_context, TEST_NAV);
  }

  static void _singleAction() {
    DynatraceRootAction myAction =
        Dynatrace().enterAction("MyButton tapped - Single Action");
    //Perform the action and whatever else is needed.
    myAction.leaveAction();
  }

  static void _subAction() {
    DynatraceRootAction myAction =
        Dynatrace().enterAction("MyButton tapped - Sub Action");
    DynatraceAction mySubAction = myAction.enterAction("MyButton Sub Action");
    //Perform the action and whatever else is needed.
    mySubAction.leaveAction();
    myAction.leaveAction();
  }

  static void _webAction() async {
    DynatraceRootAction action =
        Dynatrace().enterAction("MyButton tapped - Web Action");
    await HttpClient()
        .getUrl(Uri.parse('https://dynatrace.com'))
        .then((request) => request.close())
        .then((response) => print("Request Done"));
    action.leaveAction();
  }

  static void _reportAll() {
    DynatraceRootAction myAction =
        Dynatrace().enterAction("MyButton tapped - Report values");
    myAction.reportStringValue("ValueNameString", "ImportantValue");
    myAction.reportIntValue("ValueNameInt", 1234);
    myAction.reportDoubleValue("ValueNameDouble", 123.4567);
    myAction.reportEvent("ValueNameEvent");
    myAction.reportError("ValueNameError", 408);
    myAction.leaveAction();
  }

  static void _forceErrors() {
    String input = '12,34';
    double.parse(input);
  }

  static void _reportCrash() {
    Dynatrace().reportCrash(
        "FormatException", "Invalid Double", "WHOLE_STACKTRACE_AS_STRING");
  }

  static void _flushData() {
    Dynatrace().flushEvents();
  }

  static void _tagUser() {
    Dynatrace().identifyUser("User XY");
  }

  static void _endSession() {
    Dynatrace().endSession();
  }

  static void _setGpsLocationHawaii() {
    // set GPS coords to Hawaii
    Dynatrace().setGPSLocation(19, 155);
  }

  static void _collectionOff() {
    Dynatrace().setDataCollectionLevel(DataCollectionLevel.Off);
  }

  static void _collectionPerformance() {
    Dynatrace().setDataCollectionLevel(DataCollectionLevel.Performance);
  }

  static void _collectionUserBehavior() {
    Dynatrace().setDataCollectionLevel(DataCollectionLevel.User);
  }

  static void _crashOptedInTrue() {
    Dynatrace().setCrashReportingOptedIn(true);
  }

  static void _crashOptedInFalse() {
    Dynatrace().setCrashReportingOptedIn(false);
  }

  static Future<DataCollectionLevel> _getCollectionLevel() async {
    Future<DataCollectionLevel> dataColLevel =
        Dynatrace().getDataCollectionLevel();
    return dataColLevel;
  }

  static Future<bool> _getCrashReportingOptIn() async {
    Future<bool> crashReportingValue = Dynatrace().isCrashReportingOptedIn();
    return crashReportingValue;
  }
}
22
likes
0
pub points
96%
popularity

Publisher

verified publisherdynatrace.com

The Dynatrace Flutter plugin helps auto-instrument your Flutter app with Dynatrace OneAgent for Android and iOS. It also provides an API to add manual instrumentation.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, path, xml, yaml

More

Packages that depend on dynatrace_flutter_plugin