Skip to content

Commit ab6b8d0

Browse files
committed
add set language capability to example app
- Add a field and button to the example app to allow setting language.
1 parent f4aed5e commit ab6b8d0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

example/lib/main.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class _MyAppState extends State<MyApp> {
1616
String? _emailAddress;
1717
String? _smsNumber;
1818
String? _externalUserId;
19+
String? _language;
1920
bool _enableConsentButton = false;
2021

2122
// CHANGE THIS parameter to true if you want to test GDPR privacy consent
@@ -184,6 +185,18 @@ class _MyAppState extends State<MyApp> {
184185
});
185186
}
186187

188+
void _handleSetLanguage() {
189+
if (_language == null) return;
190+
191+
print("Setting language");
192+
193+
OneSignal.shared.setLanguage(_language!).then((response) {
194+
print("Successfully set language with response: $response");
195+
}).catchError((error) {
196+
print("Failed to set language with error: $error");
197+
});
198+
}
199+
187200
void _handleLogoutEmail() {
188201
print("Logging out of email");
189202

@@ -510,6 +523,30 @@ class _MyAppState extends State<MyApp> {
510523
new OneSignalButton(
511524
"Remove External User ID", _handleRemoveExternalUserId, !_enableConsentButton)
512525
]),
526+
new TableRow(children: [
527+
new TextField(
528+
textAlign: TextAlign.center,
529+
decoration: InputDecoration(
530+
hintText: "Language",
531+
labelStyle: TextStyle(
532+
color: Color.fromARGB(255, 212, 86, 83),
533+
)),
534+
onChanged: (text) {
535+
this.setState(() {
536+
_language = text == "" ? null : text;
537+
});
538+
},
539+
)
540+
]),
541+
new TableRow(children: [
542+
Container(
543+
height: 8.0,
544+
)
545+
]),
546+
new TableRow(children: [
547+
new OneSignalButton(
548+
"Set Language", _handleSetLanguage, !_enableConsentButton)
549+
]),
513550
new TableRow(children: [
514551
new Container(
515552
child: new Text(_debugLabelString),

0 commit comments

Comments
 (0)