repro_flutter 0.0.1 copy "repro_flutter: ^0.0.1" to clipboard
repro_flutter: ^0.0.1 copied to clipboard

outdated

Repro plugin for Flutter

example/lib/main.dart

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

import 'package:repro_flutter/repro.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final userIdController = TextEditingController();

  String _userID;
  String _deviceID;
  String _logLevel;

  @override
  void dispose() {
    userIdController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    getUserID();
    getDeviceID();
  }

  Future<void> getUserID() async {
    String userID = await Repro.userID;
    if (!mounted) return;
    setState(() {
      _userID = userID;
    });
  }

  Future<void> getDeviceID() async {
    //
    // ======== Device ID ========
    //
    // See https://docs.repro.io/en/dev/sdk/device-id.html
    //
    String deviceID = await Repro.deviceID;
    if (!mounted) return;
    setState(() {
      _deviceID = deviceID;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('ReproDev'),
          ),
          body: Center(
            child: ListView(
                padding: const EdgeInsets.all(8.0),
                children: <Widget>[
                  Text('Device ID: $_deviceID'),
                  Row(
                    children: <Widget>[
                      const Text('log level'),
                      SizedBox(width: 4),
                      DropdownButton<String>(
                        value: _logLevel,
                        onChanged: (String newValue) {
                          //
                          // ======== Log Level ========
                          //
                          // See https://docs.repro.io/en/dev/sdk/log.html
                          //
                          switch (newValue) {
                            case 'Debug':
                              Repro.logLevel = LogLevel.debug;
                              break;
                            case 'Info':
                              Repro.logLevel = LogLevel.info;
                              break;
                            case 'Warn':
                              Repro.logLevel = LogLevel.warn;
                              break;
                            case 'Error':
                              Repro.logLevel = LogLevel.error;
                              break;
                          }
                          setState(() {
                            _logLevel = newValue;
                          });
                        },
                        items: <String>['Debug', 'Info', 'Warn', 'Error']
                            .map<DropdownMenuItem<String>>((String value) {
                          return DropdownMenuItem<String>(
                            value: value,
                            child: Text(value),
                          );
                        }).toList(),
                      ),
                    ],
                  ),
                  Row(
                      children: <Widget>[
                        RaisedButton(
                          onPressed: () {
                            //
                            // ======== User ID ========
                            //
                            // See https://docs.repro.io/en/dev/sdk/user-id.html
                            //
                            Repro.userID = userIdController.text;
                            getUserID();
                          },
                          child: const Text('Set User ID'),
                        ),
                        const SizedBox(width: 4),
                        Flexible(child:TextField(
                            controller: userIdController,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              hintText: '$_userID',
                            )
                        )),
                      ]
                  ),
                  RaisedButton(
                    onPressed: () {
                      //
                      // ======== User Profile ========
                      //
                      // See https://docs.repro.io/en/dev/sdk/user-profile.html
                      //
                      Repro.setStringUserProfile("name", "Foo Bar");
                      Repro.setIntUserProfile("score", 1234);
                      Repro.setDoubleUserProfile("balance", 123.456);
                      Repro.setDateUserProfile("registration_date", DateTime.now());
                      Repro.setUserGender(UserGender.female);
                      Repro.setUserEmailAddress("foo@repro.io");
                    },
                    child: const Text('Set User Profiles'),
                  ),
                  RaisedButton(
                    onPressed: () {
                      //
                      // ======== Event Tracking ========
                      //
                      // See https://docs.repro.io/en/dev/sdk/tracking.html#id1
                      //
                      Repro.track("Track Events Button Pressed");
                      Repro.trackViewContent("example_item_id", {
                        "value": 123.456,
                        "currency": "dollar",
                        "content_name": "protein",
                        "content_category": "healthcare",
                        "extras": {
                          "volumn": 1000
                        }
                      });
                    },
                    child: const Text('Track Events'),
                  ),
                  Row(
                    //
                    // ======== Opt-In/Out ========
                    //
                    // See https://docs.repro.io/en/dev/sdk/optout/index.html
                    //
                    children: <Widget>[
                      RaisedButton(
                        onPressed: () {
                          Repro.optIn(true);
                        },
                        child: const Text('Opt-In'),
                      ),
                      const SizedBox(width: 4),
                      RaisedButton(
                        onPressed: () {
                          Repro.optIn(false);
                        },
                        child: const Text('Opt-Out'),
                      ),
                    ],
                  ),
                ]
            ),
          ),
        )
    );
  }
}
6
likes
0
points
2.26k
downloads

Publisher

unverified uploader

Weekly Downloads

Repro plugin for Flutter

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on repro_flutter