From 77366f37126ee3961b60c0d2c62d014a1f7d5ff6 Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Sat, 12 Aug 2023 17:59:06 +0400 Subject: [PATCH] Fix queue --- .../src/feature/chat/widget/chat_room.dart | 156 +++++++++--------- lib/src/client/spinify.dart | 6 +- .../client_subscription_impl.dart | 9 +- .../server_subscription_impl.dart | 3 +- 4 files changed, 83 insertions(+), 91 deletions(-) diff --git a/example/lib/src/feature/chat/widget/chat_room.dart b/example/lib/src/feature/chat/widget/chat_room.dart index b60f9d3..4192a4d 100644 --- a/example/lib/src/feature/chat/widget/chat_room.dart +++ b/example/lib/src/feature/chat/widget/chat_room.dart @@ -54,15 +54,12 @@ class _ChatRoomState extends State { } @override - Widget build(BuildContext context) => Stack( + Widget build(BuildContext context) => Column( children: [ - Positioned.fill( + Expanded( child: ListView.builder( scrollDirection: Axis.vertical, - padding: const EdgeInsets.only( - top: 16, - bottom: 84, - ), + padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 8), reverse: true, itemCount: 1000, itemBuilder: (context, index) => ListTile( @@ -70,86 +67,85 @@ class _ChatRoomState extends State { ), ), ), - Align( - alignment: Alignment.bottomCenter, - child: Padding( - padding: const EdgeInsets.only( - left: 8, - right: 8, - bottom: 16, - ), - child: SizedBox( - width: 480, - height: 48, - child: StateConsumer( - controller: _connectionController, - builder: (context, connectionState, _) => - StateConsumer( - controller: _messagesController, - listener: (context, previous, current) { - switch (current) { - case ChatMessagesState$Successful state: - _textEditingController.clear(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(state.message), - ), - ); - case ChatMessagesState$Error state: - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(state.message), - backgroundColor: Colors.red, + const Divider(height: 1, thickness: .5), + SizedBox( + height: 64, + child: ColoredBox( + color: Colors.grey.withOpacity(0.2), + child: Column( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: StateConsumer( + controller: _connectionController, + builder: (context, connectionState, _) => + StateConsumer( + controller: _messagesController, + listener: (context, previous, current) { + switch (current) { + case ChatMessagesState$Successful _: + _textEditingController.clear(); + case ChatMessagesState$Error state: + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(state.message), + backgroundColor: Colors.red, + ), + ); + default: + break; + } + }, + builder: (context, messagesState, child) => Row( + children: [ + Expanded( + child: TextField( + controller: _textEditingController, + enabled: connectionState.isConnected, + decoration: const InputDecoration( + border: InputBorder.none, + hintText: 'Write a message...', + ), + ), ), - ); - default: - break; - } - }, - builder: (context, messagesState, child) => Row( - children: [ - Expanded( - child: TextField( - controller: _textEditingController, - enabled: connectionState.isConnected, - decoration: const InputDecoration( - border: OutlineInputBorder(), - hintText: 'Enter a search term', + ValueListenableBuilder( + valueListenable: _textEditingController, + builder: (context, value, _) { + final enabled = connectionState.isConnected && + messagesState.isIdling && + value.text.isNotEmpty; + return IconButton( + icon: AnimatedSwitcher( + duration: + const Duration(milliseconds: 350), + child: switch (connectionState) { + ChatConnectionState$Connecting _ => + const CircularProgressIndicator(), + ChatConnectionState$Connected _ => + const Icon(Icons.send), + ChatConnectionState$Disconnected _ => + const Icon(Icons.send_outlined), + }, + ), + onPressed: enabled + ? () => _messagesController.sendMessage( + widget.user, + 'Hello World', + ) + : null, + ); + }, ), - ), + ], ), - ValueListenableBuilder( - valueListenable: _textEditingController, - builder: (context, value, _) { - final enabled = connectionState.isConnected && - messagesState.isIdling && - value.text.isNotEmpty; - return IconButton( - icon: AnimatedSwitcher( - duration: const Duration(milliseconds: 350), - child: switch (connectionState) { - ChatConnectionState$Connecting _ => - const CircularProgressIndicator(), - ChatConnectionState$Connected _ => - const Icon(Icons.send), - ChatConnectionState$Disconnected _ => - const Icon(Icons.send_outlined), - }, - ), - onPressed: enabled - ? () => _messagesController.sendMessage( - widget.user, - 'Hello World', - ) - : null, - ); - }, - ), - ], + ), ), ), ), - )), + ], + ), + ), ), ], ); diff --git a/lib/src/client/spinify.dart b/lib/src/client/spinify.dart index 6455ad8..8db7a26 100644 --- a/lib/src/client/spinify.dart +++ b/lib/src/client/spinify.dart @@ -66,7 +66,7 @@ final class Spinify extends SpinifyBase SpinifyPresenceMixin, SpinifyHistoryMixin, SpinifyRPCMixin, - /* SpinifyQueueMixin, */ + SpinifyQueueMixin, SpinifyMetricsMixin { /// {@macro spinify} Spinify([SpinifyConfig? config]) : super(config ?? SpinifyConfig.byDefault()); @@ -800,8 +800,8 @@ base mixin SpinifyQueueMixin on SpinifyBase { Future publish(String channel, List data) => _eventQueue.push('publish', () => super.publish(channel, data)); - @override - FutureOr ready() => _eventQueue.push('ready', super.ready); + /* @override + FutureOr ready() => _eventQueue.push('ready', super.ready); */ @override Future presence(String channel) => diff --git a/lib/src/subscription/client_subscription_impl.dart b/lib/src/subscription/client_subscription_impl.dart index be20e55..640c720 100644 --- a/lib/src/subscription/client_subscription_impl.dart +++ b/lib/src/subscription/client_subscription_impl.dart @@ -38,7 +38,8 @@ final class SpinifyClientSubscriptionImpl extends SpinifyClientSubscriptionBase SpinifyClientSubscriptionSubscribeMixin, SpinifyClientSubscriptionPublishingMixin, SpinifyClientSubscriptionHistoryMixin, - SpinifyClientSubscriptionPresenceMixin /* SpinifyClientSubscriptionQueueMixin */ { + SpinifyClientSubscriptionPresenceMixin, + SpinifyClientSubscriptionQueueMixin { /// {@nodoc} SpinifyClientSubscriptionImpl({ required super.channel, @@ -563,12 +564,6 @@ base mixin SpinifyClientSubscriptionQueueMixin /// {@nodoc} final SpinifyEventQueue _eventQueue = SpinifyEventQueue(); - @override - FutureOr ready() => _eventQueue.push( - 'ready', - super.ready, - ); - @override Future subscribe() => _eventQueue.push( 'subscribe', diff --git a/lib/src/subscription/server_subscription_impl.dart b/lib/src/subscription/server_subscription_impl.dart index acdef11..555098e 100644 --- a/lib/src/subscription/server_subscription_impl.dart +++ b/lib/src/subscription/server_subscription_impl.dart @@ -36,7 +36,8 @@ final class SpinifyServerSubscriptionImpl extends SpinifyServerSubscriptionBase SpinifyServerSubscriptionReadyMixin, SpinifyServerSubscriptionPublishingMixin, SpinifyServerSubscriptionHistoryMixin, - SpinifyServerSubscriptionPresenceMixin /* SpinifyServerSubscriptionQueueMixin */ { + SpinifyServerSubscriptionPresenceMixin, + SpinifyServerSubscriptionQueueMixin { /// {@nodoc} SpinifyServerSubscriptionImpl({ required super.channel,