Skip to content

Commit a2e00f3

Browse files
CubeRomanMagellanMagellan
andauthored
SK-645: Update UI for Search screen (#110)
* update search form * fix Forward message screen --------- Co-authored-by: Magellan <magellan@connectycube.com>
1 parent a022cad commit a2e00f3

12 files changed

Lines changed: 241 additions & 352 deletions

File tree

sama_chat_client/lib/src/features/conversation/view/messages_list.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -397,27 +397,16 @@ class MessageItem extends StatelessWidget {
397397
leadingIcon: const Icon(Icons.forward_outlined),
398398
title: const Text('Forward'),
399399
onPressed: () {
400-
print('forward message= ${message.body}');
401400
showModalBottomSheet<dynamic>(
402401
isScrollControlled: true,
403-
useSafeArea: false,
404402
context: context,
405-
backgroundColor: black,
403+
backgroundColor: Colors.transparent,
406404
builder: (BuildContext bc) {
407-
return Container(
408-
color: lightWhite,
409-
margin: EdgeInsets.only(
410-
top: MediaQueryData.fromView(
411-
View.of(context))
412-
.padding
413-
.top),
414-
child: BlocProvider.value(
415-
value:
416-
BlocProvider.of<ConversationBloc>(
417-
context),
418-
child:
419-
ForwardMessagesWidget({message}),
420-
));
405+
return BlocProvider.value(
406+
value: BlocProvider.of<ConversationBloc>(
407+
context),
408+
child: ForwardMessagesWidget({message}),
409+
);
421410
});
422411
}),
423412
FocusedPopupMenuItem(
Lines changed: 43 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_bloc/flutter_bloc.dart';
35
import 'package:go_router/go_router.dart';
@@ -6,13 +8,11 @@ import '../../../../db/models/models.dart';
68
import '../../../../navigation/constants.dart';
79
import '../../../../shared/ui/colors.dart';
810
import '../../../conversation_create/bloc/conversation_create_bloc.dart';
9-
import '../../../conversation_create/bloc/conversation_create_event.dart';
1011
import '../../../conversation_create/bloc/conversation_create_state.dart';
11-
import '../../../conversations_list/conversations_list.dart';
12-
import '../../../conversations_list/widgets/avatar_letter_icon.dart';
1312
import '../../../search/bloc/global_search_bloc.dart';
1413
import '../../../search/bloc/global_search_state.dart';
1514
import '../../../search/view/search_bar.dart';
15+
import '../../../search/view/search_form.dart';
1616
import '../../bloc/conversation_bloc.dart';
1717
import '../../bloc/forward_message/forward_messages_bloc.dart';
1818
import '../../models/chat_message.dart';
@@ -27,12 +27,34 @@ class ForwardSearchForm extends StatelessWidget {
2727

2828
@override
2929
Widget build(BuildContext context) {
30-
return Column(
31-
children: <Widget>[
32-
const GlobalSearchBar(withBack: false),
33-
_SearchBody(forwardMessages),
34-
],
35-
);
30+
final window = WidgetsBinding.instance.platformDispatcher.views.first;
31+
double topPadding = window.viewPadding.top / window.devicePixelRatio -
32+
(Platform.isIOS ? 30 : 15);
33+
return ClipRRect(
34+
borderRadius: const BorderRadius.vertical(
35+
top: Radius.circular(28),
36+
),
37+
child: Scaffold(
38+
appBar: AppBar(
39+
backgroundColor: black,
40+
automaticallyImplyLeading: false,
41+
centerTitle: true,
42+
toolbarHeight: kToolbarHeight + topPadding,
43+
title: Padding(
44+
padding: EdgeInsets.only(top: topPadding + 5),
45+
child: const Text(
46+
'Forward message',
47+
style: TextStyle(color: white),
48+
))),
49+
body: Container(
50+
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
51+
child: Column(
52+
spacing: 4,
53+
children: [
54+
const GlobalSearchBar(),
55+
_SearchBody(forwardMessages),
56+
],
57+
))));
3658
}
3759
}
3860

@@ -116,7 +138,12 @@ class _SearchBody extends StatelessWidget {
116138
padding: EdgeInsets.only(top: 18.0),
117139
child: Text('Please start typing to find chat'),
118140
)
119-
: Expanded(child: _SearchResults(null, chats, forwardMessages)),
141+
: Expanded(
142+
child: SearchResults(null, chats, chatOnTap: (chat) {
143+
context
144+
.read<ForwardMessagesBloc>()
145+
.add(SendForwardMessage([chat], forwardMessages));
146+
})),
120147
SearchStateLoading() => const Padding(
121148
padding: EdgeInsets.only(top: 18.0),
122149
child: CircularProgressIndicator.adaptive(),
@@ -126,114 +153,15 @@ class _SearchBody extends StatelessWidget {
126153
child: Text(state.error),
127154
),
128155
SearchStateSuccess() => Expanded(
129-
child: _SearchResults(
130-
state.users, state.conversations, forwardMessages)),
156+
child: SearchResults(state.users, state.conversations,
157+
chatOnTap: (chat) {
158+
context
159+
.read<ForwardMessagesBloc>()
160+
.add(SendForwardMessage([chat], forwardMessages));
161+
})),
131162
};
132163
},
133164
),
134165
);
135166
}
136167
}
137-
138-
class _SearchResults extends StatelessWidget {
139-
final List<UserModel>? users;
140-
final List<ConversationModel> chats;
141-
final Set<ChatMessage> forwardMessages;
142-
143-
const _SearchResults(this.users, this.chats, this.forwardMessages);
144-
145-
Widget _header(String title) {
146-
return Padding(
147-
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
148-
child: Container(
149-
padding: const EdgeInsets.only(left: 18.0),
150-
width: double.maxFinite,
151-
color: gainsborough, //define the background color
152-
child: Text(
153-
title,
154-
style: const TextStyle(fontSize: 18),
155-
),
156-
),
157-
);
158-
}
159-
160-
Widget _emptyListText(String title) {
161-
return Padding(
162-
padding: const EdgeInsets.all(10.0),
163-
child: Text(
164-
title,
165-
style: const TextStyle(
166-
fontWeight: FontWeight.w300,
167-
fontSize: 16,
168-
),
169-
textAlign: TextAlign.center,
170-
),
171-
);
172-
}
173-
174-
@override
175-
Widget build(BuildContext context) {
176-
final userList = users == null
177-
? null
178-
: users!.isEmpty
179-
? _emptyListText('We couldn\'t find the specified users')
180-
: ListView.builder(
181-
physics: const NeverScrollableScrollPhysics(),
182-
shrinkWrap: true,
183-
itemCount: users!.length,
184-
itemBuilder: (BuildContext context, int index) {
185-
final user = users![index];
186-
return ListTile(
187-
leading: AvatarLetterIcon(
188-
name: user.login!, avatar: user.avatar),
189-
title: Text(
190-
user.login!,
191-
style: const TextStyle(
192-
fontWeight: FontWeight.w500, fontSize: 20),
193-
maxLines: 1,
194-
overflow: TextOverflow.ellipsis,
195-
),
196-
contentPadding:
197-
const EdgeInsets.fromLTRB(18.0, 8.0, 18.0, 8.0),
198-
onTap: () {
199-
context
200-
.read<ConversationCreateBloc>()
201-
.add(ConversationCreated(user: user, type: 'u'));
202-
},
203-
);
204-
},
205-
);
206-
207-
final conversationList = chats.isEmpty
208-
? _emptyListText('We couldn\'t find the specified chats')
209-
: ListView.builder(
210-
physics: const NeverScrollableScrollPhysics(),
211-
shrinkWrap: true,
212-
itemCount: chats.length,
213-
itemBuilder: (BuildContext context, int index) {
214-
final conversation = chats[index];
215-
return ConversationListItem(
216-
conversation: conversation,
217-
onTap: () {
218-
context
219-
.read<ForwardMessagesBloc>()
220-
.add(SendForwardMessage([conversation], forwardMessages));
221-
},
222-
);
223-
},
224-
);
225-
226-
return MediaQuery.removePadding(
227-
context: context,
228-
removeTop: true,
229-
child: ListView(
230-
padding: const EdgeInsets.only(top: 10.0),
231-
children: <Widget>[
232-
if (userList != null) ...[_header('Users'), userList],
233-
_header('Chats'),
234-
conversationList,
235-
],
236-
),
237-
);
238-
}
239-
}

sama_chat_client/lib/src/features/conversation/widgets/select_input.dart

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,15 @@ class _SelectInputState extends State<SelectInput> {
121121
context,
122122
() => showModalBottomSheet<dynamic>(
123123
isScrollControlled: true,
124-
useSafeArea: false,
125124
context: context,
126-
backgroundColor: black,
125+
backgroundColor: Colors.transparent,
127126
builder: (BuildContext bc) {
128-
return Container(
129-
color: lightWhite,
130-
margin: EdgeInsets.only(
131-
top: MediaQueryData.fromView(
132-
View.of(context))
133-
.padding
134-
.top),
135-
child: BlocProvider.value(
136-
value:
137-
BlocProvider.of<ConversationBloc>(
138-
context),
139-
child: ForwardMessagesWidget(
140-
state.selectedMessages.value),
141-
));
127+
return BlocProvider.value(
128+
value: BlocProvider.of<ConversationBloc>(
129+
context),
130+
child: ForwardMessagesWidget(
131+
state.selectedMessages.value),
132+
);
142133
}));
143134
},
144135
),

sama_chat_client/lib/src/features/conversation_create/view/conversation_create_form.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,28 @@ class ConversationCreateFormState extends State<ConversationCreateForm> {
2323
@override
2424
Widget build(BuildContext context) {
2525
return Scaffold(
26-
appBar: const GlobalSearchBar(),
26+
appBar: AppBar(
27+
backgroundColor: black,
28+
iconTheme: const IconThemeData(
29+
color: white,
30+
),
31+
title: const Text(
32+
'Create chat',
33+
style: TextStyle(color: white),
34+
),
35+
centerTitle: true,
36+
),
2737
body: Container(
28-
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 4),
38+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
2939
child: Column(
3040
mainAxisSize: MainAxisSize.min,
3141
crossAxisAlignment: CrossAxisAlignment.start,
3242
children: [
43+
const GlobalSearchBar(),
3344
Row(children: <Widget>[
3445
Expanded(
3546
child: Padding(
36-
padding: const EdgeInsets.only(top: 20.0, bottom: 16.0),
47+
padding: const EdgeInsets.fromLTRB(15, 20, 15, 16),
3748
child: TextButton.icon(
3849
style: const ButtonStyle(
3950
backgroundColor: WidgetStatePropertyAll(slateBlue),
@@ -65,7 +76,7 @@ class ConversationCreateFormState extends State<ConversationCreateForm> {
6576
),
6677
),
6778
),
68-
SearchBody(searchType: SearchType.users)
79+
SearchForm(searchType: SearchType.both)
6980
]))
7081
]),
7182
));

sama_chat_client/lib/src/features/conversation_group_create/view/group_create_form.dart

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,38 @@ class GroupCreateFormState extends State<GroupCreateForm> {
3434
@override
3535
Widget build(BuildContext context) {
3636
return Scaffold(
37-
appBar: const GlobalSearchBar(),
38-
body: Container(
39-
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 4),
40-
child: BlocListener<GroupBloc, GroupState>(
41-
listener: (context, state) {
42-
if (state.status.isInitial) {
43-
} else if (state.status.isFailure) {
44-
ScaffoldMessenger.of(context)
45-
..hideCurrentSnackBar()
46-
..showSnackBar(
47-
SnackBar(content: Text(state.errorMessage ?? '')),
48-
);
49-
} else if (state.status.isSuccess) {
50-
context
51-
.read<ConversationCreateBloc>()
52-
.add(ConversationGroupCreated(
53-
users: state.participants.value.toList(),
54-
type: 'g',
55-
name: state.groupname.value,
56-
avatarUrl: state.avatar.value,
57-
));
58-
}
59-
},
37+
appBar: AppBar(
38+
backgroundColor: black,
39+
leading: const BackButton(color: white),
40+
centerTitle: true,
41+
title: const Text(
42+
'Group create',
43+
style: TextStyle(color: white),
44+
)),
45+
body: BlocListener<GroupBloc, GroupState>(
46+
listener: (context, state) {
47+
if (state.status.isInitial) {
48+
} else if (state.status.isFailure) {
49+
ScaffoldMessenger.of(context)
50+
..hideCurrentSnackBar()
51+
..showSnackBar(
52+
SnackBar(content: Text(state.errorMessage ?? '')),
53+
);
54+
} else if (state.status.isSuccess) {
55+
context
56+
.read<ConversationCreateBloc>()
57+
.add(ConversationGroupCreated(
58+
users: state.participants.value.toList(),
59+
type: 'g',
60+
name: state.groupname.value,
61+
avatarUrl: state.avatar.value,
62+
));
63+
}
64+
},
65+
child: Container(
66+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
6067
child: Column(mainAxisSize: MainAxisSize.min, children: [
68+
const GlobalSearchBar(),
6169
Expanded(
6270
child: BlocBuilder<GroupBloc, GroupState>(
6371
buildWhen: (previous, current) {

0 commit comments

Comments
 (0)