plugin_plotline 1.0.0 copy "plugin_plotline: ^1.0.0" to clipboard
plugin_plotline: ^1.0.0 copied to clipboard

Flutter Plugin for Plotline's Android SDK.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:plugin_plotline/plugin_plotline.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _plotlinePlugin = Plotline();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _plotlinePlugin.getPlatformVersion() ?? 'Unknown platform version';

    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // try {
    //    Plotline.showMockStudy();
    //    Plotline.init("NmJmN2JkYTYtMjg2OS00N2NiLTg1OTktMDI3YTdkZjYwYWU0", "test");
    //    Plotline.track("test_event");
    //   // Plotline.identify({
    //   //   "name": "testing"
    //   // });
    // } catch (e) {
    //   print(e);
    // }
    // 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;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plotline Plugin Test App'),
        ),
        body: Center(child: Column(children: <Widget> [
          Container(
            margin: EdgeInsets.all(25),
            child: Text('Running on: $_platformVersion\n'),
          ),
          Container(
            margin: EdgeInsets.all(25),
            child: FlatButton(
              child: Text('Show Mock Study', style: TextStyle(fontSize: 20.0),),
              color: Colors.blueAccent,
              textColor: Colors.white,
              onPressed: _showMockStudy,
            ),
          ),
          Container(
            margin: EdgeInsets.all(25),
            child: FlatButton(
              child: Text('Init', style: TextStyle(fontSize: 20.0),),
              color: Colors.blueAccent,
              textColor: Colors.white,
              onPressed: _init,
            ),
          ),
          Container(
            margin: EdgeInsets.all(25),
            child: FlatButton(
              child: Text('Trigger #1', style: TextStyle(fontSize: 20.0),),
              color: Colors.blueAccent,
              textColor: Colors.white,
              onPressed: _track,
            ),
          ),
        ]))
      ),
    );
  }

  _init() {
    print('Init started');
    Plotline.init("NmJmN2JkYTYtMjg2OS00N2NiLTg1OTktMDI3YTdkZjYwYWU0", "test");
  }

  _showMockStudy() {
    print('Showing Mock study');
    Plotline.showMockStudy();
  }

  _track() {
    print('Tracking test_event');
    Plotline.track("test_event");
  }
}
0
likes
130
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter Plugin for Plotline's Android SDK.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on plugin_plotline