Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/src/extensions/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,14 @@ extension BuildContextExtension on BuildContext {

/// This getter will provide the height of the text field from the
/// current context if available, otherwise it will return the
/// default height of the text field.
/// configurable fallback height from [ChatViewInheritedWidget], or the
/// [defaultChatTextFieldHeight] if no fallback is configured.
///
/// **Note**: Make sure the `chatTextFieldViewKey` is assigned to retrieve
/// actual height of text field.
double get textFieldHeight =>
chatViewIW?.chatTextFieldViewKey.currentContext?.size?.height ??
chatViewIW?.chatTextFieldHeightFallback ??
defaultChatTextFieldHeight;

ChatViewInheritedWidget? get chatViewIW =>
Expand Down
10 changes: 10 additions & 0 deletions lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:flutter/material.dart';

import '../extensions/extensions.dart';
import '../inherited_widgets/configurations_inherited_widgets.dart';
import '../utils/constants/constants.dart';
import '../utils/timeago/timeago.dart';
import '../values/custom_time_messages.dart';
import '../values/enumeration.dart';
Expand Down Expand Up @@ -65,6 +66,7 @@ class ChatView extends StatefulWidget {
this.replyMessageBuilder,
this.replySuggestionsConfig,
this.scrollToBottomButtonConfig,
this.chatTextFieldHeightFallback,
}) : chatBackgroundConfig =
chatBackgroundConfig ?? const ChatBackgroundConfiguration(),
chatViewStateConfig =
Expand Down Expand Up @@ -152,6 +154,12 @@ class ChatView extends StatefulWidget {
/// Provides a configuration for scroll to bottom button config
final ScrollToBottomButtonConfig? scrollToBottomButtonConfig;

/// Fallback height used for the bottom padding of the message list when the
/// actual chat text field height cannot be determined from the layout.
/// This is useful to prevent the last message from being hidden behind the
/// chat input field. If not provided, defaults to [defaultChatTextFieldHeight].
final double? chatTextFieldHeightFallback;

static void closeReplyMessageView(BuildContext context) {
final state = context.findAncestorStateOfType<_ChatViewState>();

Expand Down Expand Up @@ -216,6 +224,8 @@ class _ChatViewState extends State<ChatView>
featureActiveConfig: featureActiveConfig,
profileCircleConfiguration: widget.profileCircleConfig,
chatTextFieldViewKey: chatTextFieldViewKey,
chatTextFieldHeightFallback: widget.chatTextFieldHeightFallback ??
defaultChatTextFieldHeight,
child: SuggestionsConfigIW(
suggestionsConfig: widget.replySuggestionsConfig,
child: ConfigurationsInheritedWidget(
Expand Down
11 changes: 10 additions & 1 deletion lib/src/widgets/chat_view_inherited_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:flutter/material.dart';

import '../models/config_models/feature_active_config.dart';
import '../models/config_models/profile_circle_configuration.dart';
import '../utils/constants/constants.dart';
import 'reaction_popup.dart';

/// This widget for alternative of excessive amount of passing arguments
Expand All @@ -37,11 +38,18 @@ class ChatViewInheritedWidget extends InheritedWidget {
required this.chatController,
required this.chatTextFieldViewKey,
this.profileCircleConfiguration,
this.chatTextFieldHeightFallback = defaultChatTextFieldHeight,
}) : super(key: key, child: child);
final FeatureActiveConfig featureActiveConfig;
final ProfileCircleConfiguration? profileCircleConfiguration;
final ChatController chatController;
final GlobalKey chatTextFieldViewKey;

/// Fallback height used for the bottom padding of the message list when the
/// actual chat text field height cannot be determined from the layout.
/// Defaults to [defaultChatTextFieldHeight].
final double chatTextFieldHeightFallback;

final ValueNotifier<bool> showPopUp = ValueNotifier(false);
final ValueNotifier<double> chatTextFieldHeight = ValueNotifier(0.0);
final GlobalKey<ReactionPopupState> reactionPopupKey = GlobalKey();
Expand All @@ -51,5 +59,6 @@ class ChatViewInheritedWidget extends InheritedWidget {

@override
bool updateShouldNotify(covariant ChatViewInheritedWidget oldWidget) =>
oldWidget.featureActiveConfig != featureActiveConfig;
oldWidget.featureActiveConfig != featureActiveConfig ||
oldWidget.chatTextFieldHeightFallback != chatTextFieldHeightFallback;
}