feat: Added error message to new group and info tiles to new chat and merged

This commit is contained in:
Deven Joshi
2021-01-13 13:14:36 +05:30
parent 0ec0d74284
commit f3ff758894
3 changed files with 541 additions and 397 deletions
+72 -2
View File
@@ -123,10 +123,12 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
onPressed: _isGroupNameEmpty
? null
: () async {
try {
final groupName = _groupNameController.text;
final client = StreamChat.of(context).client;
final channel = client
.channel('messaging', id: Uuid().v4(), extraData: {
final channel = client.channel('messaging',
id: Uuid().v4(),
extraData: {
'members': [
client.state.user.id,
..._selectedUsers.map((e) => e.id),
@@ -140,6 +142,9 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
ModalRoute.withName(Routes.HOME),
arguments: ChannelPageArgs(channel: channel),
);
} catch (err) {
_showErrorAlert();
}
},
),
),
@@ -227,4 +232,69 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
),
);
}
void _showErrorAlert() {
showModalBottomSheet(
backgroundColor: StreamChatTheme.of(context).colorTheme.white,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
)),
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 26.0,
),
StreamSvgIcon.error(
color: StreamChatTheme.of(context).colorTheme.accentRed,
size: 24.0,
),
SizedBox(
height: 26.0,
),
Text(
'Something went wrong',
style: StreamChatTheme.of(context).textTheme.headlineBold,
),
SizedBox(
height: 7.0,
),
Text('The operation couldn\'t be completed.'),
SizedBox(
height: 36.0,
),
Container(
color:
StreamChatTheme.of(context).colorTheme.black.withOpacity(.08),
height: 1.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FlatButton(
child: Text(
'OK',
style: StreamChatTheme.of(context)
.textTheme
.bodyBold
.copyWith(
color: StreamChatTheme.of(context)
.colorTheme
.accentBlue),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
],
);
},
);
}
}
+56 -16
View File
@@ -134,7 +134,30 @@ class _NewChatScreenState extends State<NewChatScreen> {
),
centerTitle: true,
),
body: StreamChannel(
body: ValueListenableBuilder<ConnectionStatus>(
valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
String statusString = '';
bool showStatus = true;
switch (status) {
case ConnectionStatus.connected:
statusString = 'Connected';
showStatus = false;
break;
case ConnectionStatus.connecting:
statusString = 'Reconnecting...';
break;
case ConnectionStatus.disconnected:
statusString = 'Disconnected';
break;
}
return InfoTile(
showMessage: showStatus,
tileAnchor: Alignment.topCenter,
childAnchor: Alignment.topCenter,
message: statusString,
child: StreamChannel(
showLoading: false,
channel: channel,
child: Column(
@@ -162,20 +185,24 @@ class _NewChatScreenState extends State<NewChatScreen> {
),
padding: const EdgeInsets.only(left: 24),
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 4, 12, 4),
padding:
const EdgeInsets.fromLTRB(8, 4, 12, 4),
child: Text(
user.name,
maxLines: 1,
style: TextStyle(
color:
StreamChatTheme.of(context).colorTheme.black,
color: StreamChatTheme.of(context)
.colorTheme
.black,
),
),
),
),
Container(
foregroundDecoration: BoxDecoration(
color: StreamChatTheme.of(context).colorTheme.overlay,
color: StreamChatTheme.of(context)
.colorTheme
.overlay,
shape: BoxShape.circle,
),
child: UserAvatar(
@@ -225,7 +252,9 @@ class _NewChatScreenState extends State<NewChatScreen> {
SizedBox(width: 8),
Text(
'Create a Group',
style: StreamChatTheme.of(context).textTheme.bodyBold,
style: StreamChatTheme.of(context)
.textTheme
.bodyBold,
),
],
),
@@ -236,7 +265,8 @@ class _NewChatScreenState extends State<NewChatScreen> {
Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient: StreamChatTheme.of(context).colorTheme.bgGradient,
gradient:
StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
@@ -261,11 +291,13 @@ class _NewChatScreenState extends State<NewChatScreen> {
child: _showUserList
? GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) => FocusScope.of(context).unfocus(),
onPanDown: (_) =>
FocusScope.of(context).unfocus(),
child: UsersBloc(
child: UserListView(
selectedUsers: _selectedUsers,
groupAlphabetically: _isSearchActive ? false : true,
groupAlphabetically:
_isSearchActive ? false : true,
onUserTap: (user, _) {
_controller.clear();
if (!_selectedUsers.contains(user)) {
@@ -298,16 +330,20 @@ class _NewChatScreenState extends State<NewChatScreen> {
return LayoutBuilder(
builder: (context, viewportConstraints) {
return SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
physics:
AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
minHeight:
viewportConstraints.maxHeight,
),
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(24),
padding:
const EdgeInsets.all(
24),
child: StreamSvgIcon.search(
size: 96,
color: Colors.grey,
@@ -315,15 +351,17 @@ class _NewChatScreenState extends State<NewChatScreen> {
),
Text(
'No user matches these keywords...',
style: StreamChatTheme.of(context)
style: StreamChatTheme.of(
context)
.textTheme
.footnote
.copyWith(
color: StreamChatTheme.of(
context)
color: StreamChatTheme
.of(context)
.colorTheme
.black
.withOpacity(.5)),
.withOpacity(
.5)),
),
],
),
@@ -377,5 +415,7 @@ class _NewChatScreenState extends State<NewChatScreen> {
),
),
);
}),
);
}
}
+46 -12
View File
@@ -307,7 +307,33 @@ class _MessageListViewState extends State<MessageListView> {
return Stack(
alignment: Alignment.center,
children: [
LazyLoadScrollView(
ValueListenableBuilder<ConnectionStatus>(
valueListenable: _client.wsConnectionStatus,
builder: (context, status, _) {
String statusString = '';
bool showStatus = true;
switch (status) {
case ConnectionStatus.connected:
statusString = 'Connected';
showStatus = false;
break;
case ConnectionStatus.connecting:
statusString = 'Reconnecting...';
break;
case ConnectionStatus.disconnected:
statusString = 'Disconnected';
break;
}
return InfoTile(
showMessage:
widget.showConnectionStateTile ? showStatus : false,
tileAnchor: Alignment.topCenter,
childAnchor: Alignment.topCenter,
message: statusString,
child: LazyLoadScrollView(
child: LazyLoadScrollView(
onStartOfPage: () async {
_inBetweenList = false;
if (!_upToDate) {
@@ -340,17 +366,20 @@ class _MessageListViewState extends State<MessageListView> {
physics: widget.scrollPhysics,
itemScrollController: _scrollController,
reverse: true,
itemCount:
messages.length + 2 + (_isThreadConversation ? 1 : 0),
itemCount: messages.length +
2 +
(_isThreadConversation ? 1 : 0),
separatorBuilder: (context, i) {
if (i == messages.length) return Offstage();
if (i == 0) return SizedBox(height: 30);
if (i == messages.length + 1) {
final replyCount = widget.parentMessage.replyCount;
final replyCount =
widget.parentMessage.replyCount;
return Container(
decoration: BoxDecoration(
gradient:
StreamChatTheme.of(context).colorTheme.bgGradient,
gradient: StreamChatTheme.of(context)
.colorTheme
.bgGradient,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
@@ -372,15 +401,18 @@ class _MessageListViewState extends State<MessageListView> {
nextMessage.createdAt.toLocal(),
Units.DAY,
)) {
final divider = widget.dateDividerBuilder != null
final divider =
widget.dateDividerBuilder != null
? widget.dateDividerBuilder(
nextMessage.createdAt.toLocal(),
)
: DateDivider(
dateTime: nextMessage.createdAt.toLocal(),
dateTime:
nextMessage.createdAt.toLocal(),
);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
padding: const EdgeInsets.symmetric(
vertical: 12.0),
child: divider,
);
}
@@ -410,7 +442,8 @@ class _MessageListViewState extends State<MessageListView> {
widget.parentMessage,
);
} else {
return buildParentMessage(widget.parentMessage);
return buildParentMessage(
widget.parentMessage);
}
}
if (i == messages.length + 1) {
@@ -446,8 +479,8 @@ class _MessageListViewState extends State<MessageListView> {
} else {
if (widget.messageBuilder != null) {
messageWidget = Builder(
key:
ValueKey<String>('MESSAGE-${message.id}'),
key: ValueKey<String>(
'MESSAGE-${message.id}'),
builder: (context) => widget.messageBuilder(
context,
MessageDetails(
@@ -467,6 +500,7 @@ class _MessageListViewState extends State<MessageListView> {
},
),
),
),
);
}),
if (widget.showScrollToBottom) _buildScrollToBottom(),