Skip to content

Commit 35c9c65

Browse files
fadi-georgeclaude
andcommitted
chore: sync demo-pods lib with demo
demo-pods is the CocoaPods build of the same demo app, but its lib had drifted, most notably missing the in-app log view that the Appium login spec reads. Copy demo/lib over it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e881d2d commit 35c9c65

20 files changed

Lines changed: 868 additions & 502 deletions

‎examples/demo-pods/lib/main.dart‎

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
66

77
import 'screens/home_screen.dart';
88
import 'services/onesignal_api_service.dart';
9+
import 'services/log_service.dart';
910
import 'services/preferences_service.dart';
1011
import 'services/tooltip_helper.dart';
1112
import 'theme.dart';
@@ -27,7 +28,7 @@ Future<void> main() async {
2728
final appId = envAppId?.trim() ?? '';
2829
if (appId.isEmpty) {
2930
throw StateError(
30-
'ONESIGNAL_APP_ID is not set. Add it to examples/demo-pods/.env.',
31+
'ONESIGNAL_APP_ID is not set. Add it to examples/demo/.env.',
3132
);
3233
}
3334

@@ -50,47 +51,76 @@ Future<void> main() async {
5051

5152
// Register IAM listeners
5253
OneSignal.InAppMessages.addWillDisplayListener((event) {
53-
debugPrint('IAM will display: ${event.message.messageId}');
54+
LogService.show('IAM willDisplay: ${event.message.messageId}');
5455
});
5556
OneSignal.InAppMessages.addDidDisplayListener((event) {
56-
debugPrint('IAM did display: ${event.message.messageId}');
57+
LogService.show('IAM didDisplay: ${event.message.messageId}');
5758
});
5859
OneSignal.InAppMessages.addWillDismissListener((event) {
59-
debugPrint('IAM will dismiss: ${event.message.messageId}');
60+
LogService.show('IAM willDismiss: ${event.message.messageId}');
6061
});
6162
OneSignal.InAppMessages.addDidDismissListener((event) {
62-
debugPrint('IAM did dismiss: ${event.message.messageId}');
63+
LogService.show('IAM didDismiss: ${event.message.messageId}');
6364
});
6465
OneSignal.InAppMessages.addClickListener((event) {
65-
debugPrint('IAM clicked: ${event.message.messageId}');
66+
LogService.show('IAM click: ${event.message.messageId}');
6667
});
6768

6869
// Register notification listeners
6970
OneSignal.Notifications.addClickListener((event) {
70-
debugPrint('Notification clicked: ${event.notification.title}');
71+
LogService.show(
72+
'Notification click: ${event.notification.notificationId} '
73+
'${event.notification.title ?? ''}',
74+
);
75+
76+
// Uncomment to see the full event object.
77+
// debugPrint('[OneSignal] click event: ${event.jsonRepresentation()}');
7178
});
79+
7280
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
73-
debugPrint(
74-
'Notification foreground will display: ${event.notification.title}',
81+
LogService.show(
82+
'Notification foregroundWillDisplay: '
83+
'${event.notification.notificationId} ${event.notification.title ?? ''}',
7584
);
76-
event.notification.display();
85+
86+
// Uncomment to see the full event object.
87+
// debugPrint('[OneSignal] will display event: ${event.notification.jsonRepresentation()}');
88+
89+
// Uncomment to test preventing the default display behavior.
90+
// event.preventDefault();
91+
92+
// Can be called after preventDefault (within ~25 seconds) to force display.
93+
// event.notification.display();
94+
95+
// Example with a delay (assumes preventDefault was called).
96+
// debugPrint('[OneSignal] Forcing notification display in 24 seconds');
97+
// () async {
98+
// var seconds = 24;
99+
// while (seconds > 0) {
100+
// await Future<void>.delayed(const Duration(seconds: 1));
101+
// seconds--;
102+
// debugPrint('[OneSignal] Displaying notification in $seconds seconds');
103+
// }
104+
// event.notification.display();
105+
// }();
77106
});
78107

79108
// Set up API service
80109
String apiKey = '';
81110
try {
82111
apiKey = dotenv.env['ONESIGNAL_API_KEY'] ?? '';
83112
} catch (_) {
84-
debugPrint('API key not found, continuing without it');
113+
debugPrint('[OneSignal] API key not found, continuing without it');
85114
}
86-
final apiService = OneSignalApiService()
87-
..setAppId(appId)
88-
..setApiKey(apiKey);
115+
final apiService =
116+
OneSignalApiService()
117+
..setAppId(appId)
118+
..setApiKey(apiKey);
89119

90120
// Fetch tooltips in background
91121
TooltipHelper().init();
92122

93-
debugPrint('OneSignal initialized with app ID: $appId');
123+
debugPrint('[OneSignal] Initialized with app ID: $appId');
94124

95125
runApp(
96126
ChangeNotifierProvider(

‎examples/demo-pods/lib/screens/home_screen.dart‎

Lines changed: 81 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../theme.dart';
77
import '../services/tooltip_helper.dart';
88
import '../viewmodels/app_viewmodel.dart';
99
import '../widgets/dialogs.dart';
10+
import '../widgets/log_view.dart';
1011
import '../widgets/sections/aliases_section.dart';
1112
import '../widgets/sections/app_section.dart';
1213
import '../widgets/sections/user_section.dart';
@@ -77,68 +78,88 @@ class _HomeScreenState extends State<HomeScreen> {
7778
],
7879
),
7980
),
80-
body: Semantics(
81-
identifier: 'main_scroll_view',
82-
child: ListView(
83-
padding: const EdgeInsets.only(bottom: 24),
84-
children: [
85-
const AppSection(),
86-
const UserSection(),
87-
PushSection(onInfoTap: () => _showTooltipDialog(context, 'push')),
88-
SendPushSection(
89-
onInfoTap:
90-
() => _showTooltipDialog(context, 'sendPushNotification'),
91-
),
92-
InAppSection(
93-
onInfoTap: () => _showTooltipDialog(context, 'inAppMessaging'),
94-
),
95-
SendIamSection(
96-
onInfoTap: () => _showTooltipDialog(context, 'sendInAppMessage'),
97-
),
98-
AliasesSection(
99-
onInfoTap: () => _showTooltipDialog(context, 'aliases'),
100-
),
101-
EmailsSection(
102-
onInfoTap: () => _showTooltipDialog(context, 'emails'),
103-
),
104-
SmsSection(onInfoTap: () => _showTooltipDialog(context, 'sms')),
105-
TagsSection(onInfoTap: () => _showTooltipDialog(context, 'tags')),
106-
OutcomesSection(
107-
onInfoTap: () => _showTooltipDialog(context, 'outcomes'),
108-
),
109-
TriggersSection(
110-
onInfoTap: () => _showTooltipDialog(context, 'triggers'),
111-
),
112-
CustomEventsSection(
113-
onInfoTap: () => _showTooltipDialog(context, 'customEvents'),
114-
),
115-
LocationSection(
116-
onInfoTap: () => _showTooltipDialog(context, 'location'),
117-
),
118-
if (defaultTargetPlatform == TargetPlatform.iOS)
119-
LiveActivitiesSection(
120-
onInfoTap: () => _showTooltipDialog(context, 'liveActivities'),
121-
),
122-
const SizedBox(height: 8),
123-
Padding(
124-
padding: const EdgeInsets.symmetric(horizontal: 16),
125-
child: ElevatedButton(
126-
onPressed: () {
127-
Navigator.push(
128-
context,
129-
MaterialPageRoute(builder: (_) => const SecondaryScreen()),
130-
);
131-
},
132-
style: ElevatedButton.styleFrom(
133-
backgroundColor: AppColors.osPrimary,
134-
foregroundColor: Colors.white,
135-
),
136-
child: const Text('NEXT SCREEN'),
81+
body: Column(
82+
children: [
83+
const LogView(),
84+
Expanded(
85+
child: Semantics(
86+
identifier: 'main_scroll_view',
87+
child: ListView(
88+
padding: const EdgeInsets.only(bottom: 24),
89+
children: [
90+
const AppSection(),
91+
const UserSection(),
92+
PushSection(
93+
onInfoTap: () => _showTooltipDialog(context, 'push'),
94+
),
95+
SendPushSection(
96+
onInfoTap:
97+
() =>
98+
_showTooltipDialog(context, 'sendPushNotification'),
99+
),
100+
InAppSection(
101+
onInfoTap:
102+
() => _showTooltipDialog(context, 'inAppMessaging'),
103+
),
104+
SendIamSection(
105+
onInfoTap:
106+
() => _showTooltipDialog(context, 'sendInAppMessage'),
107+
),
108+
AliasesSection(
109+
onInfoTap: () => _showTooltipDialog(context, 'aliases'),
110+
),
111+
EmailsSection(
112+
onInfoTap: () => _showTooltipDialog(context, 'emails'),
113+
),
114+
SmsSection(
115+
onInfoTap: () => _showTooltipDialog(context, 'sms'),
116+
),
117+
TagsSection(
118+
onInfoTap: () => _showTooltipDialog(context, 'tags'),
119+
),
120+
OutcomesSection(
121+
onInfoTap: () => _showTooltipDialog(context, 'outcomes'),
122+
),
123+
TriggersSection(
124+
onInfoTap: () => _showTooltipDialog(context, 'triggers'),
125+
),
126+
CustomEventsSection(
127+
onInfoTap:
128+
() => _showTooltipDialog(context, 'customEvents'),
129+
),
130+
LocationSection(
131+
onInfoTap: () => _showTooltipDialog(context, 'location'),
132+
),
133+
if (defaultTargetPlatform == TargetPlatform.iOS)
134+
LiveActivitiesSection(
135+
onInfoTap:
136+
() => _showTooltipDialog(context, 'liveActivities'),
137+
),
138+
const SizedBox(height: 8),
139+
Padding(
140+
padding: const EdgeInsets.symmetric(horizontal: 16),
141+
child: ElevatedButton(
142+
onPressed: () {
143+
Navigator.push(
144+
context,
145+
MaterialPageRoute(
146+
builder: (_) => const SecondaryScreen(),
147+
),
148+
);
149+
},
150+
style: ElevatedButton.styleFrom(
151+
backgroundColor: AppColors.osPrimary,
152+
foregroundColor: Colors.white,
153+
),
154+
child: const Text('NEXT SCREEN'),
155+
),
156+
),
157+
const SizedBox(height: 16),
158+
],
137159
),
138160
),
139-
const SizedBox(height: 16),
140-
],
141-
),
161+
),
162+
],
142163
),
143164
);
144165
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter/foundation.dart';
2+
3+
class LogEntry {
4+
const LogEntry(this.time, this.message);
5+
6+
final String time;
7+
final String message;
8+
}
9+
10+
class LogService {
11+
static const _maxEntries = 100;
12+
13+
/// Log view entries are kept in memory only, so each launch starts empty.
14+
static final ValueNotifier<List<LogEntry>> entries = ValueNotifier(const []);
15+
16+
static void info(String message) => _write(message);
17+
18+
static void show(String message) {
19+
_write(message);
20+
_addToView(message);
21+
}
22+
23+
static void error(String message) {
24+
_write('ERROR: $message');
25+
_addToView(message);
26+
}
27+
28+
static void _write(String message) => debugPrint('[OneSignal] $message');
29+
30+
static void _addToView(String message) {
31+
final next = [
32+
...entries.value,
33+
LogEntry(_formatTime(DateTime.now()), message),
34+
];
35+
entries.value =
36+
next.length > _maxEntries
37+
? next.sublist(next.length - _maxEntries)
38+
: next;
39+
}
40+
41+
static void clear() => entries.value = const [];
42+
43+
static String _formatTime(DateTime date) => [
44+
date.hour,
45+
date.minute,
46+
date.second,
47+
].map((part) => part.toString().padLeft(2, '0')).join(':');
48+
49+
LogService._();
50+
}

‎examples/demo-pods/lib/theme.dart‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ class AppColors {
2020
static const osDivider = Color(0xFFE8EAED);
2121
static const osWarningBackground = Color(0xFFFFF8E1);
2222
static const osBackdrop = Color(0x8A000000);
23-
static const osLogBackground = Color(0xFF1A1B1E);
24-
static const osLogDebug = Color(0xFF82AAFF);
25-
static const osLogInfo = Color(0xFFC3E88D);
26-
static const osLogWarn = Color(0xFFFFCB6B);
27-
static const osLogError = Color(0xFFFF5370);
28-
static const osLogTimestamp = Color(0xFF676E7B);
23+
static const osLogBackground = Color(0xFF1E1E1E);
24+
static const osLogText = Color(0xFFD4D4D4);
2925
AppColors._();
3026
}
3127

@@ -79,8 +75,11 @@ class AppTheme {
7975
disabledForegroundColor: AppColors.osGrey500,
8076
),
8177
),
78+
// Top-anchored: a dialog that moves while open desyncs XCUITest frame
79+
// reporting from the rendered layout.
8280
dialogTheme: const DialogThemeData(
8381
backgroundColor: Colors.white,
82+
alignment: Alignment.topCenter,
8483
),
8584
dividerColor: AppColors.osDivider,
8685
inputDecorationTheme: InputDecorationTheme(

0 commit comments

Comments
 (0)