From 5afc274a6d8ff7091c700ffb048c47224f8af561 Mon Sep 17 00:00:00 2001 From: groovinchip Date: Thu, 29 Jul 2021 10:48:52 -0400 Subject: [PATCH] chore: add lerp, hashcode, ==, and diagnosticable to message_input_theme.dart --- .../lib/src/message_actions_modal.dart | 3 +- .../lib/src/message_input.dart | 4 +- .../lib/src/stream_chat_theme.dart | 2 +- .../lib/src/theme/message_input_theme.dart | 92 +++++++++++++++++-- 4 files changed, 91 insertions(+), 10 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart index efaf0ded..11d96e77 100644 --- a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart +++ b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart @@ -562,7 +562,8 @@ class _MessageActionsModalState extends State { elevation: 2, clipBehavior: Clip.hardEdge, isScrollControlled: true, - backgroundColor: streamChatThemeData.messageInputTheme.inputBackground, + backgroundColor: + streamChatThemeData.messageInputTheme.inputBackgroundColor, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.only( topLeft: Radius.circular(16), diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index 5a4f6822..2030f47a 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -328,7 +328,7 @@ class MessageInputState extends State { Widget build(BuildContext context) { Widget child = DecoratedBox( decoration: BoxDecoration( - color: _streamChatTheme.messageInputTheme.inputBackground, + color: _streamChatTheme.messageInputTheme.inputBackgroundColor, ), child: SafeArea( child: GestureDetector( @@ -565,7 +565,7 @@ class MessageInputState extends State { child: DecoratedBox( decoration: BoxDecoration( borderRadius: _streamChatTheme.messageInputTheme.borderRadius, - color: _streamChatTheme.messageInputTheme.inputBackground, + color: _streamChatTheme.messageInputTheme.inputBackgroundColor, ), child: Column( mainAxisSize: MainAxisSize.min, diff --git a/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart b/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart index 98a6e156..3f9c39fe 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart @@ -378,7 +378,7 @@ class StreamChatThemeData { expandButtonColor: colorTheme.accentPrimary, sendButtonColor: colorTheme.accentPrimary, sendButtonIdleColor: colorTheme.disabled, - inputBackground: colorTheme.barsBg, + inputBackgroundColor: colorTheme.barsBg, inputTextStyle: textTheme.body, idleBorderGradient: LinearGradient( colors: [ diff --git a/packages/stream_chat_flutter/lib/src/theme/message_input_theme.dart b/packages/stream_chat_flutter/lib/src/theme/message_input_theme.dart index 09c99478..1d14c1b9 100644 --- a/packages/stream_chat_flutter/lib/src/theme/message_input_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/message_input_theme.dart @@ -1,8 +1,9 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:stream_chat_flutter/src/extension.dart'; /// Defines the theme dedicated to the [MessageInput] widget -class MessageInputTheme { +class MessageInputTheme with Diagnosticable { /// Returns a new [MessageInputTheme] const MessageInputTheme({ this.sendAnimationDuration, @@ -10,7 +11,7 @@ class MessageInputTheme { this.sendButtonColor, this.actionButtonIdleColor, this.sendButtonIdleColor, - this.inputBackground, + this.inputBackgroundColor, this.inputTextStyle, this.inputDecoration, this.activeBorderGradient, @@ -38,7 +39,7 @@ class MessageInputTheme { final Color? expandButtonColor; /// Background color of [MessageInput] - final Color? inputBackground; + final Color? inputBackgroundColor; /// TextStyle of [MessageInput] final TextStyle? inputTextStyle; @@ -58,7 +59,7 @@ class MessageInputTheme { /// Returns a new [MessageInputTheme] replacing some of its properties MessageInputTheme copyWith({ Duration? sendAnimationDuration, - Color? inputBackground, + Color? inputBackgroundColor, Color? actionButtonColor, Color? sendButtonColor, Color? actionButtonIdleColor, @@ -73,7 +74,7 @@ class MessageInputTheme { MessageInputTheme( sendAnimationDuration: sendAnimationDuration ?? this.sendAnimationDuration, - inputBackground: inputBackground ?? this.inputBackground, + inputBackgroundColor: inputBackgroundColor ?? this.inputBackgroundColor, actionButtonColor: actionButtonColor ?? this.actionButtonColor, sendButtonColor: sendButtonColor ?? this.sendButtonColor, actionButtonIdleColor: @@ -87,12 +88,40 @@ class MessageInputTheme { borderRadius: borderRadius ?? this.borderRadius, ); + /// Linearly interpolate from one [MessageInputTheme] to another. + MessageInputTheme lerp( + MessageInputTheme a, + MessageInputTheme b, + double t, + ) => + MessageInputTheme( + actionButtonColor: + Color.lerp(a.actionButtonColor, b.actionButtonColor, t), + actionButtonIdleColor: + Color.lerp(a.actionButtonIdleColor, b.actionButtonIdleColor, t), + activeBorderGradient: + Gradient.lerp(a.activeBorderGradient, b.activeBorderGradient, t), + borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t), + expandButtonColor: + Color.lerp(a.expandButtonColor, b.expandButtonColor, t), + idleBorderGradient: + Gradient.lerp(a.idleBorderGradient, b.idleBorderGradient, t), + inputBackgroundColor: + Color.lerp(a.inputBackgroundColor, b.inputBackgroundColor, t), + inputTextStyle: TextStyle.lerp(a.inputTextStyle, b.inputTextStyle, t), + sendButtonColor: Color.lerp(a.sendButtonColor, b.sendButtonColor, t), + sendButtonIdleColor: + Color.lerp(a.sendButtonIdleColor, b.sendButtonIdleColor, t), + sendAnimationDuration: a.sendAnimationDuration, + inputDecoration: a.inputDecoration, + ); + /// Merges [this] [MessageInputTheme] with the [other] MessageInputTheme merge(MessageInputTheme? other) { if (other == null) return this; return copyWith( sendAnimationDuration: other.sendAnimationDuration, - inputBackground: other.inputBackground, + inputBackgroundColor: other.inputBackgroundColor, actionButtonColor: other.actionButtonColor, actionButtonIdleColor: other.actionButtonIdleColor, sendButtonColor: other.sendButtonColor, @@ -107,4 +136,55 @@ class MessageInputTheme { expandButtonColor: other.expandButtonColor, ); } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is MessageInputTheme && + runtimeType == other.runtimeType && + sendAnimationDuration == other.sendAnimationDuration && + sendButtonColor == other.sendButtonColor && + actionButtonColor == other.actionButtonColor && + sendButtonIdleColor == other.sendButtonIdleColor && + actionButtonIdleColor == other.actionButtonIdleColor && + expandButtonColor == other.expandButtonColor && + inputBackgroundColor == other.inputBackgroundColor && + inputTextStyle == other.inputTextStyle && + inputDecoration == other.inputDecoration && + idleBorderGradient == other.idleBorderGradient && + activeBorderGradient == other.activeBorderGradient && + borderRadius == other.borderRadius; + + @override + int get hashCode => + sendAnimationDuration.hashCode ^ + sendButtonColor.hashCode ^ + actionButtonColor.hashCode ^ + sendButtonIdleColor.hashCode ^ + actionButtonIdleColor.hashCode ^ + expandButtonColor.hashCode ^ + inputBackgroundColor.hashCode ^ + inputTextStyle.hashCode ^ + inputDecoration.hashCode ^ + idleBorderGradient.hashCode ^ + activeBorderGradient.hashCode ^ + borderRadius.hashCode; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('sendAnimationDuration', sendAnimationDuration)) + ..add(ColorProperty('inputBackgroundColor', inputBackgroundColor)) + ..add(ColorProperty('actionButtonColor', actionButtonColor)) + ..add(ColorProperty('actionButtonIdleColor', actionButtonIdleColor)) + ..add(ColorProperty('sendButtonColor', sendButtonColor)) + ..add(ColorProperty('sendButtonIdleColor', sendButtonIdleColor)) + ..add(DiagnosticsProperty('inputTextStyle', inputTextStyle)) + ..add(DiagnosticsProperty('inputDecoration', inputDecoration)) + ..add(DiagnosticsProperty('activeBorderGradient', activeBorderGradient)) + ..add(DiagnosticsProperty('idleBorderGradient', idleBorderGradient)) + ..add(DiagnosticsProperty('borderRadius', borderRadius)) + ..add(ColorProperty('expandButtonColor', expandButtonColor)); + } }