repro_flutter 1.3.0
repro_flutter: ^1.3.0 copied to clipboard
A plugin for using the Repro Android/iOS SDK in your Flutter app.
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.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 'Debug':
await Repro.setLogLevel(LogLevel.debug);
break;
case 'Info':
await Repro.setLogLevel(LogLevel.info);
break;
case 'Warn':
await Repro.setLogLevel(LogLevel.warn);
break;
case 'Error':
await Repro.setLogLevel(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: () 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',
))),
]),
RaisedButton(
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'),
),
RaisedButton(
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'),
),
RaisedButton(
onPressed: () async {
//
// ======== NewsFeeds ========
//
var newsFeeds = await Repro.getNewsFeeds(20);
for (var feed in newsFeeds) {
debugPrint('[NewsFeed]'
' id: ${feed.id},'
' 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'),
),
RaisedButton(
onPressed: () async {
//
// ======== UX Optimizer ========
//
var values = await Repro.remoteConfig.getAllValues();
if (values != null) {
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>[
RaisedButton(
onPressed: () async {
await Repro.optIn(true);
},
child: const Text('Opt-In'),
),
const SizedBox(width: 4),
RaisedButton(
onPressed: () async {
await Repro.optIn(false);
},
child: const Text('Opt-Out'),
),
],
),
]),
),
));
}
}