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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
- name: Static Analysis
run: flutter analyze

- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '17'

- name: Setup Clang
uses: OneSignal/sdk-shared/.github/actions/setup-clang@main

Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ analyzer:
- example_pod/**
- example_spm/**
- examples/**
- build/**
- android/**
- ios/**
5 changes: 5 additions & 0 deletions examples/demo/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
24 changes: 13 additions & 11 deletions examples/demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:provider/provider.dart';

import 'screens/home_screen.dart';
import 'services/onesignal_api_service.dart';
import 'services/log_service.dart';
import 'services/preferences_service.dart';
import 'services/tooltip_helper.dart';
import 'theme.dart';
Expand Down Expand Up @@ -48,35 +49,36 @@ Future<void> main() async {

// Register IAM listeners
OneSignal.InAppMessages.addWillDisplayListener((event) {
debugPrint('[OneSignal] IAM willDisplay: ${event.message.messageId}');
LogService.show('IAM willDisplay: ${event.message.messageId}');
});
OneSignal.InAppMessages.addDidDisplayListener((event) {
debugPrint('[OneSignal] IAM didDisplay: ${event.message.messageId}');
LogService.show('IAM didDisplay: ${event.message.messageId}');
});
OneSignal.InAppMessages.addWillDismissListener((event) {
debugPrint('[OneSignal] IAM willDismiss: ${event.message.messageId}');
LogService.show('IAM willDismiss: ${event.message.messageId}');
});
OneSignal.InAppMessages.addDidDismissListener((event) {
debugPrint('[OneSignal] IAM didDismiss: ${event.message.messageId}');
LogService.show('IAM didDismiss: ${event.message.messageId}');
});
OneSignal.InAppMessages.addClickListener((event) {
debugPrint('[OneSignal] IAM click: ${event.message.messageId}');
LogService.show('IAM click: ${event.message.messageId}');
});

// Register notification listeners
OneSignal.Notifications.addClickListener((event) {
debugPrint(
'[OneSignal] Notification click: ${event.notification.title ?? ''}',
LogService.show(
'Notification click: ${event.notification.notificationId} '
'${event.notification.title ?? ''}',
);

// Uncomment to see the full event object.
// debugPrint('[OneSignal] click event: ${event.jsonRepresentation()}');
});

OneSignal.Notifications.addForegroundWillDisplayListener((event) {
debugPrint(
'[OneSignal] Notification foregroundWillDisplay: '
'${event.notification.title ?? ''}',
LogService.show(
'Notification foregroundWillDisplay: '
'${event.notification.notificationId} ${event.notification.title ?? ''}',
);

// Uncomment to see the full event object.
Expand Down
141 changes: 81 additions & 60 deletions examples/demo/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../theme.dart';
import '../services/tooltip_helper.dart';
import '../viewmodels/app_viewmodel.dart';
import '../widgets/dialogs.dart';
import '../widgets/log_view.dart';
import '../widgets/sections/aliases_section.dart';
import '../widgets/sections/app_section.dart';
import '../widgets/sections/user_section.dart';
Expand Down Expand Up @@ -77,68 +78,88 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
),
body: Semantics(
identifier: 'main_scroll_view',
child: ListView(
padding: const EdgeInsets.only(bottom: 24),
children: [
const AppSection(),
const UserSection(),
PushSection(onInfoTap: () => _showTooltipDialog(context, 'push')),
SendPushSection(
onInfoTap:
() => _showTooltipDialog(context, 'sendPushNotification'),
),
InAppSection(
onInfoTap: () => _showTooltipDialog(context, 'inAppMessaging'),
),
SendIamSection(
onInfoTap: () => _showTooltipDialog(context, 'sendInAppMessage'),
),
AliasesSection(
onInfoTap: () => _showTooltipDialog(context, 'aliases'),
),
EmailsSection(
onInfoTap: () => _showTooltipDialog(context, 'emails'),
),
SmsSection(onInfoTap: () => _showTooltipDialog(context, 'sms')),
TagsSection(onInfoTap: () => _showTooltipDialog(context, 'tags')),
OutcomesSection(
onInfoTap: () => _showTooltipDialog(context, 'outcomes'),
),
TriggersSection(
onInfoTap: () => _showTooltipDialog(context, 'triggers'),
),
CustomEventsSection(
onInfoTap: () => _showTooltipDialog(context, 'customEvents'),
),
LocationSection(
onInfoTap: () => _showTooltipDialog(context, 'location'),
),
if (defaultTargetPlatform == TargetPlatform.iOS)
LiveActivitiesSection(
onInfoTap: () => _showTooltipDialog(context, 'liveActivities'),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (_) => const SecondaryScreen()),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.osPrimary,
foregroundColor: Colors.white,
),
child: const Text('NEXT SCREEN'),
body: Column(
children: [
const LogView(),
Expanded(
child: Semantics(
identifier: 'main_scroll_view',
child: ListView(
padding: const EdgeInsets.only(bottom: 24),
children: [
const AppSection(),
const UserSection(),
PushSection(
onInfoTap: () => _showTooltipDialog(context, 'push'),
),
SendPushSection(
onInfoTap:
() =>
_showTooltipDialog(context, 'sendPushNotification'),
),
InAppSection(
onInfoTap:
() => _showTooltipDialog(context, 'inAppMessaging'),
),
SendIamSection(
onInfoTap:
() => _showTooltipDialog(context, 'sendInAppMessage'),
),
AliasesSection(
onInfoTap: () => _showTooltipDialog(context, 'aliases'),
),
EmailsSection(
onInfoTap: () => _showTooltipDialog(context, 'emails'),
),
SmsSection(
onInfoTap: () => _showTooltipDialog(context, 'sms'),
),
TagsSection(
onInfoTap: () => _showTooltipDialog(context, 'tags'),
),
OutcomesSection(
onInfoTap: () => _showTooltipDialog(context, 'outcomes'),
),
TriggersSection(
onInfoTap: () => _showTooltipDialog(context, 'triggers'),
),
CustomEventsSection(
onInfoTap:
() => _showTooltipDialog(context, 'customEvents'),
),
LocationSection(
onInfoTap: () => _showTooltipDialog(context, 'location'),
),
if (defaultTargetPlatform == TargetPlatform.iOS)
LiveActivitiesSection(
onInfoTap:
() => _showTooltipDialog(context, 'liveActivities'),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const SecondaryScreen(),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.osPrimary,
foregroundColor: Colors.white,
),
child: const Text('NEXT SCREEN'),
),
),
const SizedBox(height: 16),
],
),
),
const SizedBox(height: 16),
],
),
),
],
),
);
}
Expand Down
50 changes: 50 additions & 0 deletions examples/demo/lib/services/log_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/foundation.dart';

class LogEntry {
const LogEntry(this.time, this.message);

final String time;
final String message;
}

class LogService {
static const _maxEntries = 100;

/// Log view entries are kept in memory only, so each launch starts empty.
static final ValueNotifier<List<LogEntry>> entries = ValueNotifier(const []);

static void info(String message) => _write(message);

static void show(String message) {
_write(message);
_addToView(message);
}

static void error(String message) {
_write('ERROR: $message');
_addToView(message);
}

static void _write(String message) => debugPrint('[OneSignal] $message');

static void _addToView(String message) {
final next = [
...entries.value,
LogEntry(_formatTime(DateTime.now()), message),
];
entries.value =
next.length > _maxEntries
? next.sublist(next.length - _maxEntries)
: next;
}

static void clear() => entries.value = const [];

static String _formatTime(DateTime date) => [
date.hour,
date.minute,
date.second,
].map((part) => part.toString().padLeft(2, '0')).join(':');

LogService._();
}
8 changes: 2 additions & 6 deletions examples/demo/lib/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ class AppColors {
static const osDivider = Color(0xFFE8EAED);
static const osWarningBackground = Color(0xFFFFF8E1);
static const osBackdrop = Color(0x8A000000);
static const osLogBackground = Color(0xFF1A1B1E);
static const osLogDebug = Color(0xFF82AAFF);
static const osLogInfo = Color(0xFFC3E88D);
static const osLogWarn = Color(0xFFFFCB6B);
static const osLogError = Color(0xFFFF5370);
static const osLogTimestamp = Color(0xFF676E7B);
static const osLogBackground = Color(0xFF1E1E1E);
static const osLogText = Color(0xFFD4D4D4);
AppColors._();
}

Expand Down
Loading
Loading