-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.dart
83 lines (76 loc) · 2.33 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:braze_plugin_web/braze_plugin_web.dart';
/// Set the Braze API Key and Base URL with Dart Environment Variables
/// Run Args: --dart-define=apiKey=1234567890 --dart-define=baseUrl=sdk.iad-02.braze.com
void main() => runApp(MyApp());
const String _brazeApiKey = String.fromEnvironment('apiKey');
const String _brazeBaseUrl = String.fromEnvironment('baseUrl');
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Braze Plugin for Web',
home: BrazeWebExamplePage(),
);
}
}
class BrazeWebExamplePage extends StatefulWidget {
@override
BrazeWebExamplePageState createState() => new BrazeWebExamplePageState();
}
class BrazeWebExamplePageState extends State<BrazeWebExamplePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Braze Web Example'),
),
body: Column(
children: [
TextButton(
child: const Text('Initialize'),
onPressed: () async {
BrazeClient.initialize(
apiKey: _brazeApiKey,
baseUrl: _brazeBaseUrl,
automaticallyShowInAppMessages: true,
enableLogging: true,
);
},
),
TextButton(
child: const Text('Identify'),
onPressed: () async {
BrazeClient.identify('test-user');
},
),
TextButton(
child: const Text('Set Custom Attribute'),
onPressed: () async {
BrazeClient.setCustomAttribute('test_web_plugin', true);
},
),
TextButton(
child: const Text('Set Custom Attributes'),
onPressed: () async {
BrazeClient.setCustomAttributes({
'test_web_plugin_1': 'Hi!',
'test_web_plugin_2': 27,
});
},
),
TextButton(
child: const Text('Log Custom Event'),
onPressed: () async {
BrazeClient.logCustomEvent(
'test_web_plugin_event',
jsonEncode({'prop1': false}),
);
},
),
],
),
);
}
}