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
38 changes: 23 additions & 15 deletions lib/src/models/notification_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter/material.dart';

/// Class representing the data structure of a notification.
Expand Down Expand Up @@ -63,24 +65,30 @@ class MessageData {
this.subHeader,
});

/// Factory method to create MessageData from JSON.
factory MessageData.fromJson(Map<String, dynamic>? json) {
/// Factory method to create MessageData from data.
factory MessageData.fromJson(Map<String, dynamic>? data) {
Map<String, dynamic>? additionalData;
if (data?['additionalData'] != null) {
try {
additionalData = json.decode(data?['additionalData'] as String)
as Map<String, dynamic>?;
} catch (error) {
additionalData = null;
}
}
return MessageData(
channel: json?['channel'] as String?,
header: json?['header'] as String?,
subHeader: json?['subHeader'] as String?,
body: json?['body'] as String?,
actionUrl: json?['actionUrl'] as String?,
avatar: json?['avatar'] != null
? AvatarData.fromJson(json?['avatar'] as Map<String, dynamic>)
channel: data?['channel'] as String?,
header: data?['header'] as String?,
subHeader: data?['subHeader'] as String?,
body: data?['body'] as String?,
actionUrl: data?['actionUrl'] as String?,
avatar: data?['avatar'] != null
? AvatarData.fromJson(data?['avatar'] as Map<String, dynamic>)
: null,
thumbnailUrl: json?['thumbnailUrl'] != null
? (json?['thumbnailUrl'] as String?)
thumbnailUrl: data?['thumbnailUrl'] != null
? (data?['thumbnailUrl'] as String?)
: '',
additionalData:
(json?['additionalData'] != null && json?['additionalData'] is Map)
? json!['additionalData'] as Map<String, dynamic>?
: null,
additionalData: additionalData,
);
}

Expand Down
90 changes: 45 additions & 45 deletions lib/src/widgets/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class SirenAppBar extends StatelessWidget implements PreferredSizeWidget {
: null,
),
height: preferredSize.height,
child: Padding(
padding: const EdgeInsets.only(right: 16, left: 20),
child: headerParams?.customHeader ??
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
child: headerParams?.customHeader ??
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(right: 16, left: 20),
child: Row(
children: [
if (headerParams?.showBackButton ?? false)
Semantics(
Expand Down Expand Up @@ -93,49 +93,49 @@ class SirenAppBar extends StatelessWidget implements PreferredSizeWidget {
),
],
),
if (!(headerParams?.hideClearAll ?? false))
Semantics(
label: 'siren-header-clear-all',
hint: 'Tap to clear all notifications',
child: GestureDetector(
key: const Key('siren-header-clear-all'),
onTap: () {
if (isNonEmptyNotifications &&
onClearAllPressed != null) {
onClearAllPressed!();
}
},
child: Opacity(
opacity: isNonEmptyNotifications ? 1 : 0.4,
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 4),
child: Icon(
Icons.clear_all,
size: styles?.clearAllIconStyle?.size ?? 24,
color: colors?.clearAllIcon ??
defaultColors.appBarActionText,
),
),
if (!(headerParams?.hideClearAll ?? false))
Semantics(
label: 'siren-header-clear-all',
hint: 'Tap to clear all notifications',
child: GestureDetector(
key: const Key('siren-header-clear-all'),
onTap: () {
if (isNonEmptyNotifications &&
onClearAllPressed != null) {
onClearAllPressed!();
}
},
child: Opacity(
opacity: isNonEmptyNotifications ? 1 : 0.4,
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 4),
child: Icon(
Icons.clear_all,
size: styles?.clearAllIconStyle?.size ?? 24,
color: colors?.clearAllIcon ??
defaultColors.appBarActionText,
),
Text(
Strings.clear_all,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: colors?.inboxHeaderColors
?.headerActionColor ??
defaultColors.appBarActionText,
),
),
Text(
Strings.clear_all,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: colors
?.inboxHeaderColors?.headerActionColor ??
defaultColors.appBarActionText,
),
],
),
),
],
),
),
),
],
),
),
),
],
),
);
}
}
8 changes: 4 additions & 4 deletions test/models/notification_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() {
'body': 'body',
'actionUrl': 'actionUrl',
'avatar': {'imageUrl': 'avatarUrl', 'altText': 'altText'},
'additionalData': <String, dynamic>{},
'additionalData': '{}',
},
'requestId': 'requestId',
'isRead': true,
Expand All @@ -37,7 +37,7 @@ void main() {
expect(notification.message.actionUrl, 'actionUrl');
expect(notification.message.avatar?.url, 'avatarUrl');
expect(notification.message.avatar?.altText, 'altText');
expect(notification.message.additionalData, {});
expect(notification.message.additionalData, isA<Map<String, dynamic>>());
});

test('markAsRead() should mark the notification as read', () {
Expand Down Expand Up @@ -77,7 +77,7 @@ void main() {
'body': 'body',
'actionUrl': 'actionUrl',
'avatar': {'imageUrl': 'avatarUrl', 'altText': 'altText'},
'additionalData': <String, dynamic>{},
'additionalData': '{}',
};

final message = MessageData.fromJson(Map<String, dynamic>.from(json));
Expand All @@ -89,7 +89,7 @@ void main() {
expect(message.actionUrl, 'actionUrl');
expect(message.avatar?.url, 'avatarUrl');
expect(message.avatar?.altText, 'altText');
expect(message.additionalData, {});
expect(message.additionalData, isA<Map<String, dynamic>>());
});
});

Expand Down