@@ -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
@@ -141,6 +142,21 @@ class _MyAppState extends State<MyApp> {
141142 });
142143 }
143144
145+ void _handleSetExternalUserId () {
146+ print ("Setting external user ID" );
147+ OneSignal .shared.setExternalUserId (_externalUserId);
148+ this .setState (() {
149+ _debugLabelString = "Set External User ID" ;
150+ });
151+ }
152+
153+ void _handleRemoveExternalUserId () {
154+ OneSignal .shared.removeExternalUserId ();
155+ this .setState (() {
156+ _debugLabelString = "Removed external user ID" ;
157+ });
158+ }
159+
144160 void _handleConsent () {
145161 print ("Setting consent to true" );
146162 OneSignal .shared.consentGranted (true );
@@ -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