-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinbox.dart
More file actions
220 lines (212 loc) · 7.04 KB
/
inbox.dart
File metadata and controls
220 lines (212 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import 'package:courier_flutter/courier_flutter.dart';
import 'package:courier_flutter/ui/inbox/courier_inbox.dart';
import 'package:courier_flutter/ui/inbox/courier_inbox_theme.dart';
import 'package:courier_flutter_sample/env.dart';
import 'package:courier_flutter_sample/pages/inbox_custom.dart';
import 'package:courier_flutter_sample/theme.dart';
import 'package:flutter/material.dart';
import 'package:courier_flutter_sample/pages/full_inbox_page.dart';
class InboxPage extends StatefulWidget {
const InboxPage({super.key});
@override
State<InboxPage> createState() => _InboxState();
}
class _InboxState extends State<InboxPage> with SingleTickerProviderStateMixin {
final ScrollController _feedScrollController = ScrollController();
final ScrollController _archivedScrollController = ScrollController();
TabController? _tabController;
final customTheme = CourierInboxTheme(
unreadIndicatorStyle: const CourierInboxUnreadIndicatorStyle(
indicator: CourierInboxUnreadIndicator.dot,
color: AppTheme.primaryColor,
),
loadingIndicatorColor: AppTheme.primaryColor,
tabIndicatorColor: AppTheme.primaryColor,
tabStyle: CourierInboxTabStyle(
selected: CourierInboxTabItemStyle(
font: AppTheme.unreadTitleText.copyWith(color: AppTheme.primaryColor),
indicator: CourierInboxTabIndicatorStyle(
color: AppTheme.primaryColor,
font: AppTheme.bodyText.copyWith(color: Colors.white),
),
),
unselected: CourierInboxTabItemStyle(
font: AppTheme.titleText.copyWith(color: AppTheme.secondaryColor),
indicator: CourierInboxTabIndicatorStyle(
color: AppTheme.secondaryColor,
font: AppTheme.bodyText.copyWith(color: Colors.white),
),
),
),
readingSwipeActionStyle: CourierInboxReadingSwipeActionStyle(
read: const CourierInboxSwipeActionStyle(
icon: Icons.drafts,
color: AppTheme.primaryColor,
),
unread: CourierInboxSwipeActionStyle(
icon: Icons.mark_email_read,
color: AppTheme.primaryColor.withOpacity(0.5),
),
),
archivingSwipeActionStyle: const CourierInboxArchivingSwipeActionStyle(
archive: CourierInboxSwipeActionStyle(
icon: Icons.inbox,
color: Colors.red,
),
),
titleStyle: CourierInboxTextStyle(
read: AppTheme.titleText,
unread: AppTheme.unreadTitleText,
),
timeStyle: CourierInboxTextStyle(
read: AppTheme.bodyText,
unread: AppTheme.unreadBodyText,
),
bodyStyle: CourierInboxTextStyle(
read: AppTheme.bodyText,
unread: AppTheme.unreadBodyText,
),
buttonStyle: CourierInboxButtonStyle(
read: AppTheme.buttonStyle,
unread: AppTheme.unreadButtonStyle,
),
separator: null,
infoViewStyle: CourierInfoViewStyle(
textStyle: AppTheme.titleText,
buttonStyle: AppTheme.buttonStyle,
),
);
late final Map<String, Widget> pages = {
'Default': CourierInbox(
keepAlive: true,
onMessageClick: (message, index) {
message.isRead ? message.markAsUnread() : message.markAsRead();
},
onActionClick: (action, message, index) {
print(action);
},
),
'Branded': CourierInbox(
keepAlive: true,
lightTheme: CourierInboxTheme(
brandId: Env.brandId,
),
darkTheme: CourierInboxTheme(
brandId: Env.brandId,
),
onMessageClick: (message, index) {
message.isRead ? message.markAsUnread() : message.markAsRead();
},
),
'Styled': CourierInbox(
keepAlive: true,
showCourierFooter: false,
lightTheme: customTheme,
darkTheme: customTheme,
feedScrollController: _feedScrollController,
archivedScrollController: _archivedScrollController,
onMessageClick: (message, index) {
message.isRead ? message.markAsUnread() : message.markAsRead();
},
onMessageLongPress: (message, index) {
showModalBottomSheet(
context: context,
clipBehavior: Clip.hardEdge,
builder: (BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: Text(message.isRead ? 'Mark as unread' : 'Mark as read'),
onTap: () {
message.isRead ? message.markAsUnread() : message.markAsRead();
Navigator.pop(context);
},
),
ListTile(
title: const Text('Archive'),
onTap: () {
message.markAsArchived();
Navigator.pop(context);
},
),
ListTile(
title: const Text('Scroll to top'),
onTap: () {
_feedScrollController.jumpTo(0);
Navigator.pop(context);
},
),
ListTile(
title: const Text('Cancel'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
},
);
},
onActionClick: (action, message, index) {
print(action);
},
onError: (error) {
print(error);
return 'You can now pass a custom error message here if you want to.';
},
),
'Custom': const CustomInboxPage(),
};
@override
void initState() {
super.initState();
_tabController = TabController(length: pages.length, vsync: this);
}
@override
void dispose() {
_tabController?.dispose();
_feedScrollController.dispose();
_archivedScrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Inbox'),
actions: [
IconButton(
tooltip: 'Read All Messages',
icon: const Icon(Icons.mark_email_read), // Example icon for the button
onPressed: () => Courier.shared.readAllInboxMessages(),
),
IconButton(
tooltip: 'Open Full Inbox',
icon: const Icon(Icons.open_in_new), // Example icon for the button
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const FullInboxPage()),
);
},
),
],
bottom: TabBar(
controller: _tabController,
tabs: pages.keys.map((String title) => Tab(text: title)).toList(),
),
),
body: TabBarView(
controller: _tabController,
physics: const NeverScrollableScrollPhysics(),
children: pages.values.toList(),
),
);
}
}