1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6import 'package:provider/provider.dart';
7
8import '../../layout/adaptive.dart';
9import 'mail_card_preview.dart';
10import 'model/email_model.dart';
11import 'model/email_store.dart';
12
13class MailboxBody extends StatelessWidget {
14 const MailboxBody({super.key});
15
16 @override
17 Widget build(BuildContext context) {
18 final bool isDesktop = isDisplayDesktop(context);
19 final bool isTablet = isDisplaySmallDesktop(context);
20 final double startPadding =
21 isTablet
22 ? 60.0
23 : isDesktop
24 ? 120.0
25 : 4.0;
26 final double endPadding =
27 isTablet
28 ? 30.0
29 : isDesktop
30 ? 60.0
31 : 4.0;
32
33 return Consumer<EmailStore>(
34 builder: (BuildContext context, EmailStore model, Widget? child) {
35 final MailboxPageType destination = model.selectedMailboxPage;
36 final String destinationString = destination.toString().substring(
37 destination.toString().indexOf('.') + 1,
38 );
39
40 final List<Email> emails = switch (destination) {
41 MailboxPageType.inbox => model.inboxEmails,
42 MailboxPageType.sent => model.outboxEmails,
43 MailboxPageType.starred => model.starredEmails,
44 MailboxPageType.trash => model.trashEmails,
45 MailboxPageType.spam => model.spamEmails,
46 MailboxPageType.drafts => model.draftEmails,
47 };
48
49 return SafeArea(
50 bottom: false,
51 child: Row(
52 crossAxisAlignment: CrossAxisAlignment.start,
53 children: <Widget>[
54 Expanded(
55 child:
56 emails.isEmpty
57 ? Center(child: Text('Empty in $destinationString'))
58 : ListView.separated(
59 itemCount: emails.length,
60 padding: EdgeInsetsDirectional.only(
61 start: startPadding,
62 end: endPadding,
63 top: isDesktop ? 28 : 0,
64 bottom: kToolbarHeight,
65 ),
66 primary: false,
67 separatorBuilder:
68 (BuildContext context, int index) => const SizedBox(height: 4),
69 itemBuilder: (BuildContext context, int index) {
70 final Email email = emails[index];
71 return MailPreviewCard(
72 id: email.id,
73 email: email,
74 isStarred: model.isEmailStarred(email.id),
75 onDelete: () => model.deleteEmail(email.id),
76 onStar: () {
77 final int emailId = email.id;
78 if (model.isEmailStarred(emailId)) {
79 model.unstarEmail(emailId);
80 } else {
81 model.starEmail(emailId);
82 }
83 },
84 onStarredMailbox:
85 model.selectedMailboxPage == MailboxPageType.starred,
86 );
87 },
88 ),
89 ),
90 if (isDesktop) ...<Widget>[
91 Padding(
92 padding: const EdgeInsetsDirectional.only(top: 14),
93 child: Row(
94 children: <Widget>[
95 IconButton(
96 key: const ValueKey<String>('ReplySearch'),
97 icon: const Icon(Icons.search),
98 onPressed: () {
99 Provider.of<EmailStore>(context, listen: false).onSearchPage = true;
100 },
101 ),
102 SizedBox(width: isTablet ? 30 : 60),
103 ],
104 ),
105 ),
106 ],
107 ],
108 ),
109 );
110 },
111 );
112 }
113}
114

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com