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

A plugin for using the Repro Android/iOS SDK in your Flutter app.

example/lib/main.dart

// import 'package:firebase_core/firebase_core.dart';
// import 'package:firebase_messaging/firebase_messaging.dart';

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

import 'package:repro_flutter/repro.dart';
import 'package:repro_flutter_example/test/test_helper.dart';

void main() async {

  // Initialize FlutterFire

  // WidgetsFlutterBinding.ensureInitialized();
  // await Firebase.initializeApp();

  // Detects that the Firebase token has changed and sends the token to Repro.
  
  // FirebaseMessaging messaging = FirebaseMessaging.instance;
  // messaging.onTokenRefresh.listen((token) async {
  //   await Repro.setPushRegistrationID(token);
  // });

  runApp(MyApp());
}

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

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

  String _userID = "";
  String _deviceID = "";
  String _logLevel = "Debug";

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

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

  Future<void> getUserID() async {
    String userID = await Repro.getUserID();
    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.getDeviceID();
    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) async {
                  //
                  // ======== Log Level ========
                  //
                  // See https://docs.repro.io/en/dev/sdk/log.html
                  //
                  switch (newValue) {
                    case 'Info':
                      await Repro.setLogLevel(LogLevel.info);
                      break;
                    case 'Warn':
                      await Repro.setLogLevel(LogLevel.warn);
                      break;
                    case 'Error':
                      await Repro.setLogLevel(LogLevel.error);
                      break;
                    default:
                      await Repro.setLogLevel(LogLevel.debug);
                      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>[
            ElevatedButton(
              onPressed: () async {
                //
                // ======== User ID ========
                //
                // See https://docs.repro.io/en/dev/sdk/user-id.html
                //
                await Repro.setUserID(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',
                    ))),
          ]),
          ElevatedButton(
            onPressed: () async {
              //
              // ======== User Profile ========
              //
              // See https://docs.repro.io/en/dev/sdk/user-profile.html
              //
              await Repro.setStringUserProfile("name", "Foo Bar");
              await Repro.setIntUserProfile("score", 1234);
              await Repro.setDoubleUserProfile("balance", 123.456);
              await Repro.setDateUserProfile(
                  "registration_date", DateTime.now());
              await Repro.setUserGender(UserGender.female);
              await Repro.setUserEmailAddress("foo@repro.io");
            },
            child: const Text('Set User Profiles'),
          ),
          ElevatedButton(
            onPressed: () async {
              //
              // ======== Event Tracking ========
              //
              // See https://docs.repro.io/en/dev/sdk/tracking.html#id1
              //
              await Repro.track("Track Events Button Pressed");
              await Repro.trackViewContent("example_item_id", {
                "value": 123.456,
                "currency": "dollar",
                "content_name": "protein",
                "content_category": "healthcare",
                "extras": {"volumn": 1000}
              });
            },
            child: const Text('Track Events'),
          ),
          ElevatedButton(
            onPressed: () async {
              //
              // ======== NewsFeeds ========
              //
              var newsFeeds = await Repro.getNewsFeeds(limit: 10, campaignType: NewsFeedCampaignType.PushNotification);
              for (var feed in newsFeeds) {
                debugPrint('[NewsFeed]'
                    ' id: ${feed.id},'
                    ' campaignType: ${feed.campaignType},'
                    ' deviceID: ${feed.deviceID},'
                    ' title: ${feed.title},'
                    ' summary: ${feed.summary},'
                    ' body: ${feed.body},'
                    ' linkUrl: ${feed.linkUrl},'
                    ' imageUrl: ${feed.imageUrl},'
                    ' deliveredAt: ${feed.deliveredAt},'
                    ' read: ${feed.read},'
                    ' shown: ${feed.shown}');

              }
            },
            child: const Text('Get NewsFeeds'),
          ),
          ElevatedButton(
            onPressed: () async {
              //
              // ======== UX Optimizer ========
              //
              var values = await Repro.remoteConfig.getAllValues();
              for (var key in values.keys) {
                debugPrint('[RemoteConfig] $key: ${values[key]}');
              }
            },
            child: const Text('Get all RemoteConfig values'),
          ),
          Row(
            //
            // ======== Opt-In/Out ========
            //
            // See https://docs.repro.io/en/dev/sdk/optout/index.html
            //
            children: <Widget>[
              ElevatedButton(
                onPressed: () async {
                  await Repro.optIn(true);
                },
                child: const Text('Opt-In'),
              ),
              const SizedBox(width: 4),
              ElevatedButton(
                onPressed: () async {
                  await Repro.optIn(false);
                },
                child: const Text('Opt-Out'),
              ),
            ],
          ),
          Row(
            children: <Widget>[
              SizedBox(
                child: ElevatedButton(
                  onPressed: () async {
                    var tester = ManualAppTester();
                    tester.run();
                  },
                  child: Text("Test for debug"),
                ),
              ),
            ],
          ),

        ]),
      ),
    ));
  }
}
6
likes
0
pub points
80%
popularity

Publisher

unverified uploader

A plugin for using the Repro Android/iOS SDK in your Flutter app.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on repro_flutter