@@ -14,6 +14,7 @@ class MyApp extends StatefulWidget {
1414class _MyAppState extends State <MyApp > {
1515 String _debugLabelString = "" ;
1616 String _emailAddress;
17+ String _externalUserId;
1718 bool _enableConsentButton = false ;
1819
1920 // CHANGE THIS parameter to true if you want to test GDPR privacy consent
@@ -165,6 +166,21 @@ class _MyAppState extends State<MyApp> {
165166 });
166167 }
167168
169+ void _handleSetExternalUserId () {
170+ print ("Setting external user ID" );
171+ OneSignal .shared.setExternalUserId (_externalUserId);
172+ this .setState (() {
173+ _debugLabelString = "Set External User ID" ;
174+ });
175+ }
176+
177+ void _handleRemoveExternalUserId () {
178+ OneSignal .shared.removeExternalUserId ();
179+ this .setState (() {
180+ _debugLabelString = "Removed external user ID" ;
181+ });
182+ }
183+
168184 void _handleSendNotification () async {
169185 var status = await OneSignal .shared.getPermissionSubscriptionState ();
170186
@@ -285,12 +301,40 @@ class _MyAppState extends State<MyApp> {
285301 new OneSignalButton ("Post Silent Notification" ,
286302 _handleSendSilentNotification, ! _enableConsentButton)
287303 ]),
304+ new TableRow (children: [
305+ new TextField (
306+ textAlign: TextAlign .center,
307+ decoration: InputDecoration (
308+ hintText: "External User ID" ,
309+ labelStyle: TextStyle (
310+ color: Color .fromARGB (255 , 212 , 86 , 83 ),
311+ )),
312+ onChanged: (text) {
313+ this .setState (() {
314+ _externalUserId = text == "" ? null : text;
315+ });
316+ },
317+ )
318+ ]),
319+ new TableRow (children: [
320+ Container (
321+ height: 8.0 ,
322+ )
323+ ]),
324+ new TableRow (children: [
325+ new OneSignalButton (
326+ "Set External User ID" , _handleSetExternalUserId, ! _enableConsentButton)
327+ ]),
328+ new TableRow (children: [
329+ new OneSignalButton (
330+ "Remove External User ID" , _handleRemoveExternalUserId, ! _enableConsentButton)
331+ ]),
288332 new TableRow (children: [
289333 new Container (
290334 child: new Text (_debugLabelString),
291335 alignment: Alignment .center,
292336 )
293- ])
337+ ]),
294338 ],
295339 ),
296340 ),
0 commit comments