-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.dart
188 lines (181 loc) · 6.3 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:umeng_analytics_with_push/umeng_analytics_with_push.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _initialized;
dynamic _errorOnInit;
String _oaid;
String _utdid;
String _devToken;
String _tags;
bool get _hasDeviceToken => _devToken != null && _devToken != "Getting";
@override
void initState() {
super.initState();
_initialized = false;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [UmengAnalyticsObserver(log: !kReleaseMode)],
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: ListView(
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
children: [
ElevatedButton(
onPressed: _initialized
? null
: () {
UmengAnalyticsWithPush.initialize().then((_) {
setState(() {
_initialized = true;
});
}).catchError((e, s) {
setState(() {
_errorOnInit = e;
});
});
},
child: Text("Init"),
),
ElevatedButton(
onPressed: () {
UmengAnalyticsWithPush.oaid.then((oaid) {
setState(() {
_oaid = oaid ?? "null";
});
}).catchError((e, s) {
setState(() {
_oaid = e.toString();
});
});
},
child: Text("Got OAID"),
),
ElevatedButton(
onPressed: () {
UmengAnalyticsWithPush.utdid.then((utdid) {
setState(() {
_utdid = utdid ?? "null";
});
}).catchError((e, s) {
setState(() {
_utdid = e.toString();
});
});
},
child: Text("Got UtdId"),
),
ElevatedButton(
onPressed: !_initialized
? null
: () {
setState(() {
_devToken = "Getting";
});
UmengAnalyticsWithPush.deviceToken.then((dt) {
print("deviceToken: $dt");
setState(() {
_devToken = dt ?? "null";
});
}).catchError((e, s) {
print("deviceToken: $e" + (s != null ? "\n$s" : ""));
setState(() {
_devToken = e.toString();
});
});
},
child: Text("Got DeviceToken"),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () async {
await UmengAnalyticsWithPush.addAlias("token", "flutter");
print("addAlias ok");
},
child: Text("AddAlias type=\"token\", alias=\"flutter\""),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () async {
await UmengAnalyticsWithPush.putAlias("token", "flutter");
print("putAlias ok");
},
child: Text("PutAlias type=\"token\", alias=\"flutter\""),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () async {
await UmengAnalyticsWithPush.removeAlias(
"token", "flutter");
print("removeAlias ok");
},
child: Text("RemoveAlias type=\"token\", alias=\"flutter\""),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () {
UmengAnalyticsWithPush.getTags().then((tags) {
print("getTags: $tags");
setState(() {
_tags = tags?.join(", ") ?? "null";
});
}).catchError((e, s) {
print("getTags: $e" + (s != null ? "\n$s" : ""));
setState(() {
_tags = e.toString();
});
});
},
child: Text("getTags \"flutter_tag1\", \"flutter_tag2\""),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () {
UmengAnalyticsWithPush.addTags(
["flutter_tag1", "flutter_tag2"]);
},
child: Text("AddTags \"flutter_tag1\", \"flutter_tag2\""),
),
ElevatedButton(
onPressed: !_hasDeviceToken
? null
: () {
UmengAnalyticsWithPush.removeTags(
["flutter_tag1", "flutter_tag2"]);
},
child: Text("RemoveTags \"flutter_tag1\", \"flutter_tag2\""),
),
SizedBox(height: 16),
Text(_initialized ? "Initialized!" : "Please click Init"),
if (_oaid != null) SizedBox(height: 12),
if (_oaid != null) SelectableText("OAID: $_oaid"),
if (_utdid != null) SizedBox(height: 12),
if (_utdid != null) SelectableText("UTDID: $_utdid"),
SizedBox(height: 12),
SelectableText(_devToken == null
? "Please click Got DeviceToken"
: "DeviceToken: $_devToken"),
SizedBox(height: 12),
if (_tags != null) SelectableText("Tags: $_tags"),
],
),
),
);
}
}