-
Notifications
You must be signed in to change notification settings - Fork 2
/
contacts_screen.dart
135 lines (130 loc) · 5.25 KB
/
contacts_screen.dart
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
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:kumuly_pocket/constants.dart';
import 'package:kumuly_pocket/features/contacts/contact_list_controller.dart';
import 'package:kumuly_pocket/features/contacts/frequent_contacts_controller.dart';
import 'package:kumuly_pocket/theme/custom_theme.dart';
import 'package:kumuly_pocket/theme/palette.dart';
import 'package:kumuly_pocket/widgets/lists/contacts_list.dart';
import 'package:kumuly_pocket/widgets/lists/frequent_contacts_list.dart';
import 'package:kumuly_pocket/widgets/shadows/bottom_shadow.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ContactsScreen extends ConsumerWidget {
const ContactsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final textTheme = Theme.of(context).textTheme;
final copy = AppLocalizations.of(context)!;
double screenWidth = MediaQuery.of(context).size.width;
final frequentContactsState = ref.watch(
frequentContactsControllerProvider(kFrequentContactsLimit),
);
final frequentContactsNotifier = ref.read(
frequentContactsControllerProvider(kFrequentContactsLimit).notifier,
);
final contactListState = ref.watch(
contactListControllerProvider(kContactListLimit),
);
final contactListNotifier = ref.read(
contactListControllerProvider(kContactListLimit).notifier,
);
return Scaffold(
backgroundColor: Colors.white,
body: Padding(
padding: const EdgeInsets.only(
top: kSpacing6,
),
child: Stack(
children: [
RefreshIndicator(
onRefresh: () async {
await frequentContactsNotifier.fetchContacts(refresh: true);
await contactListNotifier.fetchContacts(refresh: true);
},
child: ListView(
padding: EdgeInsets.zero,
children: [
// Search bar
Container(
padding: const EdgeInsets.only(
left: kSpacing2,
right: kSpacing2,
),
height: 32,
color: Colors.transparent,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: Icon(
Icons.search,
color: Palette.neutral[100]!,
),
prefixIconConstraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
maxHeight: 24,
maxWidth: 24,
),
prefix: const SizedBox(width: kSpacing1),
hintText: copy.searchAContact,
hintStyle: textTheme.display2(
Palette.neutral[50],
FontWeight.w500,
),
),
style: textTheme.display3(
Palette.neutral[100],
FontWeight.w500,
),
),
),
const SizedBox(height: kSpacing5),
// Add contact + frequent/favorite contacts
SizedBox(
height: 116,
child: FrequentContactsList(
contactListItems: frequentContactsState.hasValue
? frequentContactsState.asData!.value.contacts
: [],
loadContactListItems:
frequentContactsNotifier.fetchContacts,
limit: kFrequentContactsLimit,
hasMore: frequentContactsState.hasValue
? frequentContactsState.asData!.value.hasMoreContacts
: true,
isLoading: frequentContactsState.isLoading,
isLoadingError: frequentContactsState.hasError,
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: kSpacing2,
),
child: ContactsList(
contactListItems: contactListState.hasValue
? contactListState.asData!.value.contacts
: [],
loadContactListItems: contactListNotifier.fetchContacts,
limit: kContactListLimit,
hasMore: contactListState.hasValue
? contactListState.asData!.value.hasMoreContacts
: true,
isLoading: contactListState.isLoading,
isLoadingError: contactListState.hasError,
),
),
const SizedBox(
height: kSpacing3,
),
],
),
),
BottomShadow(
width: screenWidth,
),
],
),
),
);
}
}