Skip to content

Commit 59657dc

Browse files
Version 1.3.0
Fix: Remove the extra padding from the App Bar UI and type correction for additional data
1 parent 4f44373 commit 59657dc

File tree

4 files changed

+79
-64
lines changed

4 files changed

+79
-64
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 1.3.0
6+
7+
### Added
8+
- Added a fix for the extra padding issue in the app bar when a custom header is passed.
9+
- Added a fix for parsing additional data to JSON when received as a string.
10+
11+
512
## 1.2.0
613

714
### Added

lib/src/models/notification_model.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:flutter/material.dart';
24

35
/// Class representing the data structure of a notification.
@@ -63,24 +65,30 @@ class MessageData {
6365
this.subHeader,
6466
});
6567

66-
/// Factory method to create MessageData from JSON.
67-
factory MessageData.fromJson(Map<String, dynamic>? json) {
68+
/// Factory method to create MessageData from data.
69+
factory MessageData.fromJson(Map<String, dynamic>? data) {
70+
Map<String, dynamic>? additionalData;
71+
if (data?['additionalData'] != null) {
72+
try {
73+
additionalData = json.decode(data?['additionalData'] as String)
74+
as Map<String, dynamic>?;
75+
} catch (error) {
76+
additionalData = null;
77+
}
78+
}
6879
return MessageData(
69-
channel: json?['channel'] as String?,
70-
header: json?['header'] as String?,
71-
subHeader: json?['subHeader'] as String?,
72-
body: json?['body'] as String?,
73-
actionUrl: json?['actionUrl'] as String?,
74-
avatar: json?['avatar'] != null
75-
? AvatarData.fromJson(json?['avatar'] as Map<String, dynamic>)
80+
channel: data?['channel'] as String?,
81+
header: data?['header'] as String?,
82+
subHeader: data?['subHeader'] as String?,
83+
body: data?['body'] as String?,
84+
actionUrl: data?['actionUrl'] as String?,
85+
avatar: data?['avatar'] != null
86+
? AvatarData.fromJson(data?['avatar'] as Map<String, dynamic>)
7687
: null,
77-
thumbnailUrl: json?['thumbnailUrl'] != null
78-
? (json?['thumbnailUrl'] as String?)
88+
thumbnailUrl: data?['thumbnailUrl'] != null
89+
? (data?['thumbnailUrl'] as String?)
7990
: '',
80-
additionalData:
81-
(json?['additionalData'] != null && json?['additionalData'] is Map)
82-
? json!['additionalData'] as Map<String, dynamic>?
83-
: null,
91+
additionalData: additionalData,
8492
);
8593
}
8694

lib/src/widgets/app_bar.dart

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class SirenAppBar extends StatelessWidget implements PreferredSizeWidget {
4848
: null,
4949
),
5050
height: preferredSize.height,
51-
child: Padding(
52-
padding: const EdgeInsets.only(right: 16, left: 20),
53-
child: headerParams?.customHeader ??
54-
Row(
55-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
56-
children: [
57-
Row(
51+
child: headerParams?.customHeader ??
52+
Row(
53+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
54+
children: [
55+
Padding(
56+
padding: const EdgeInsets.only(right: 16, left: 20),
57+
child: Row(
5858
children: [
5959
if (headerParams?.showBackButton ?? false)
6060
Semantics(
@@ -93,49 +93,49 @@ class SirenAppBar extends StatelessWidget implements PreferredSizeWidget {
9393
),
9494
],
9595
),
96-
if (!(headerParams?.hideClearAll ?? false))
97-
Semantics(
98-
label: 'siren-header-clear-all',
99-
hint: 'Tap to clear all notifications',
100-
child: GestureDetector(
101-
key: const Key('siren-header-clear-all'),
102-
onTap: () {
103-
if (isNonEmptyNotifications &&
104-
onClearAllPressed != null) {
105-
onClearAllPressed!();
106-
}
107-
},
108-
child: Opacity(
109-
opacity: isNonEmptyNotifications ? 1 : 0.4,
110-
child: Row(
111-
children: [
112-
Padding(
113-
padding: const EdgeInsets.only(right: 4),
114-
child: Icon(
115-
Icons.clear_all,
116-
size: styles?.clearAllIconStyle?.size ?? 24,
117-
color: colors?.clearAllIcon ??
118-
defaultColors.appBarActionText,
119-
),
96+
),
97+
if (!(headerParams?.hideClearAll ?? false))
98+
Semantics(
99+
label: 'siren-header-clear-all',
100+
hint: 'Tap to clear all notifications',
101+
child: GestureDetector(
102+
key: const Key('siren-header-clear-all'),
103+
onTap: () {
104+
if (isNonEmptyNotifications &&
105+
onClearAllPressed != null) {
106+
onClearAllPressed!();
107+
}
108+
},
109+
child: Opacity(
110+
opacity: isNonEmptyNotifications ? 1 : 0.4,
111+
child: Row(
112+
children: [
113+
Padding(
114+
padding: const EdgeInsets.only(right: 4),
115+
child: Icon(
116+
Icons.clear_all,
117+
size: styles?.clearAllIconStyle?.size ?? 24,
118+
color: colors?.clearAllIcon ??
119+
defaultColors.appBarActionText,
120120
),
121-
Text(
122-
Strings.clear_all,
123-
style: TextStyle(
124-
fontSize: 14,
125-
fontWeight: FontWeight.w500,
126-
color: colors?.inboxHeaderColors
127-
?.headerActionColor ??
128-
defaultColors.appBarActionText,
129-
),
121+
),
122+
Text(
123+
Strings.clear_all,
124+
style: TextStyle(
125+
fontSize: 14,
126+
fontWeight: FontWeight.w500,
127+
color: colors
128+
?.inboxHeaderColors?.headerActionColor ??
129+
defaultColors.appBarActionText,
130130
),
131-
],
132-
),
131+
),
132+
],
133133
),
134134
),
135135
),
136-
],
137-
),
138-
),
136+
),
137+
],
138+
),
139139
);
140140
}
141141
}

test/models/notification_model_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void main() {
1515
'body': 'body',
1616
'actionUrl': 'actionUrl',
1717
'avatar': {'imageUrl': 'avatarUrl', 'altText': 'altText'},
18-
'additionalData': <String, dynamic>{},
18+
'additionalData': '{}',
1919
},
2020
'requestId': 'requestId',
2121
'isRead': true,
@@ -37,7 +37,7 @@ void main() {
3737
expect(notification.message.actionUrl, 'actionUrl');
3838
expect(notification.message.avatar?.url, 'avatarUrl');
3939
expect(notification.message.avatar?.altText, 'altText');
40-
expect(notification.message.additionalData, {});
40+
expect(notification.message.additionalData, isA<Map<String, dynamic>>());
4141
});
4242

4343
test('markAsRead() should mark the notification as read', () {
@@ -77,7 +77,7 @@ void main() {
7777
'body': 'body',
7878
'actionUrl': 'actionUrl',
7979
'avatar': {'imageUrl': 'avatarUrl', 'altText': 'altText'},
80-
'additionalData': <String, dynamic>{},
80+
'additionalData': '{}',
8181
};
8282

8383
final message = MessageData.fromJson(Map<String, dynamic>.from(json));
@@ -89,7 +89,7 @@ void main() {
8989
expect(message.actionUrl, 'actionUrl');
9090
expect(message.avatar?.url, 'avatarUrl');
9191
expect(message.avatar?.altText, 'altText');
92-
expect(message.additionalData, {});
92+
expect(message.additionalData, isA<Map<String, dynamic>>());
9393
});
9494
});
9595

0 commit comments

Comments
 (0)