Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/demo-pods/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
analyzer:
exclude:
- build/**
- android/**
- ios/**
include: package:flutter_lints/flutter.yaml

linter:
Expand Down
11 changes: 6 additions & 5 deletions examples/demo-pods/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
Expand All @@ -15,10 +14,6 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.onesignal.example"
Expand All @@ -39,6 +34,12 @@ android {
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

flutter {
source = "../.."
}
4 changes: 4 additions & 0 deletions examples/demo-pods/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ org.gradle.caching=true
org.gradle.configureondemand=true
android.useAndroidX=true
android.nonTransitiveRClass=true
# This newDsl flag was added by the Flutter template
android.newDsl=false
# This builtInKotlin flag was added by the Flutter template
android.builtInKotlin=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
4 changes: 2 additions & 2 deletions examples/demo-pods/android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pluginManagement {

plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.11.1" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
id("com.android.application") version "9.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
}

include(":app")
11 changes: 6 additions & 5 deletions examples/demo/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
Expand All @@ -15,10 +14,6 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.onesignal.example"
Expand All @@ -39,6 +34,12 @@ android {
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

flutter {
source = "../.."
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
4 changes: 2 additions & 2 deletions examples/demo/android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pluginManagement {

plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.11.1" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
id("com.android.application") version "9.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
}

include(":app")
17 changes: 17 additions & 0 deletions examples/demo/lib/viewmodels/app_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class AppViewModel extends ChangeNotifier {
// user-change observer's fetch right after login).
int _fetchSequence = 0;

// Last identity pair seen by the User observer. Some native SDK versions
// re-fire the observer on every user model hydration (e.g. after addEmail
// or addTag), so only refetch when the identity actually changes.
String? _observedOnesignalId;
String? _observedExternalId;

// App state
String _appId = '';
String get appId => _appId;
Expand Down Expand Up @@ -149,6 +155,8 @@ class AppViewModel extends ChangeNotifier {

final onesignalId = await OneSignal.User.getOnesignalId();
_oneSignalId = onesignalId;
_observedOnesignalId ??= onesignalId;
_observedExternalId ??= await OneSignal.User.getExternalId();

notifyListeners();

Expand Down Expand Up @@ -191,9 +199,18 @@ class AppViewModel extends ChangeNotifier {
'externalId=${state.current.externalId ?? 'null'}',
);

final nextExternalId = state.current.externalId;
final identityChanged =
nextOnesignalId != _observedOnesignalId ||
nextExternalId != _observedExternalId;
_observedOnesignalId = nextOnesignalId;
_observedExternalId = nextExternalId;

_oneSignalId = nextOnesignalId;
notifyListeners();

if (!identityChanged) return;

// Drive the post-login fetch from the observer so it runs only once the
// SDK has actually assigned a new onesignalId. Logout clears it to null;
// skip the fetch in that case (logoutUser already clears local lists).
Expand Down
Loading