From 57cbd4370b9bf97dcce3d9c848c40a83170f1d23 Mon Sep 17 00:00:00 2001 From: Nutcake Date: Tue, 16 May 2023 13:20:11 +0200 Subject: [PATCH] Improve responsiveness of bottom inset in message view --- lib/widgets/messages/messages_list.dart | 172 ++++++++++++------------ 1 file changed, 85 insertions(+), 87 deletions(-) diff --git a/lib/widgets/messages/messages_list.dart b/lib/widgets/messages/messages_list.dart index 2fa75f1..09a3720 100644 --- a/lib/widgets/messages/messages_list.dart +++ b/lib/widgets/messages/messages_list.dart @@ -193,99 +193,97 @@ class _MessagesListState extends State with SingleTickerProviderSt }, ), ), - ], - ), - bottomNavigationBar: AnimatedContainer( - decoration: BoxDecoration( - boxShadow: [ - BoxShadow( - blurRadius: _showBottomBarShadow ? 8 : 0, - color: Theme.of(context).shadowColor, - offset: const Offset(0, 4), - ), - ], - color: Theme.of(context).colorScheme.background, - ), - padding: MediaQuery - .of(context) - .viewInsets + const EdgeInsets.symmetric(horizontal: 4), - duration: const Duration(milliseconds: 250), - child: Row( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.all(8), - child: TextField( - autocorrect: true, - controller: _messageTextController, - maxLines: 4, - minLines: 1, - onChanged: (text) { - if (text.isNotEmpty && !_isSendable) { - setState(() { - _isSendable = true; - }); - } else if (text.isEmpty && _isSendable) { - setState(() { - _isSendable = false; - }); - } - }, - decoration: InputDecoration( - isDense: true, - hintText: "Send a message to ${widget.friend - .username}...", - contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(24) - ) - ), + AnimatedContainer( + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + blurRadius: _showBottomBarShadow ? 8 : 0, + color: Theme.of(context).shadowColor, + offset: const Offset(0, 4), ), - ), + ], + color: Theme.of(context).colorScheme.background, ), - Padding( - padding: const EdgeInsets.only(left: 8, right: 4.0), - child: Consumer( - builder: (context, mClient, _) { - return IconButton( - splashRadius: 24, - onPressed: _isSendable ? () async { - setState(() { - _isSendable = false; - }); - final message = Message( - id: Message.generateId(), - recipientId: widget.friend.id, - senderId: apiClient.userId, - type: MessageType.text, - content: _messageTextController.text, - sendTime: DateTime.now().toUtc(), - ); - try { - mClient.sendMessage(message); - _messageTextController.clear(); - setState(() {}); - } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text("Failed to send message\n$e", - maxLines: null, - ), - ), - ); + padding: const EdgeInsets.symmetric(horizontal: 4), + duration: const Duration(milliseconds: 250), + child: Row( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.all(8), + child: TextField( + autocorrect: true, + controller: _messageTextController, + maxLines: 4, + minLines: 1, + onChanged: (text) { + if (text.isNotEmpty && !_isSendable) { setState(() { _isSendable = true; }); + } else if (text.isEmpty && _isSendable) { + setState(() { + _isSendable = false; + }); } - } : null, - iconSize: 28, - icon: const Icon(Icons.send), - ); - }, - ), - ) - ], - ), + }, + decoration: InputDecoration( + isDense: true, + hintText: "Send a message to ${widget.friend + .username}...", + contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(24) + ) + ), + ), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8, right: 4.0), + child: Consumer( + builder: (context, mClient, _) { + return IconButton( + splashRadius: 24, + onPressed: _isSendable ? () async { + setState(() { + _isSendable = false; + }); + final message = Message( + id: Message.generateId(), + recipientId: widget.friend.id, + senderId: apiClient.userId, + type: MessageType.text, + content: _messageTextController.text, + sendTime: DateTime.now().toUtc(), + ); + try { + mClient.sendMessage(message); + _messageTextController.clear(); + setState(() {}); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text("Failed to send message\n$e", + maxLines: null, + ), + ), + ); + setState(() { + _isSendable = true; + }); + } + } : null, + iconSize: 28, + icon: const Icon(Icons.send), + ); + }, + ), + ) + ], + ), + ), + ], ), ); }