ScrollBehaviorConfig class
Configuration for scroll behavior in the chat.
This class allows control over how and when the chat widget automatically scrolls, which can be important for accessibility and user experience, especially with long responses.
Example:
AiChatWidget(
// ... other parameters
scrollBehaviorConfig: ScrollBehaviorConfig(
// Only scroll for user messages, allowing manual scrolling for AI responses
autoScrollBehavior: AutoScrollBehavior.onUserMessageOnly,
// When scrolling happens for AI responses, scroll to the first message
// instead of the last (preventing the top of the response from being hidden)
scrollToFirstResponseMessage: true,
),
)
Example for very long messages:
// For handling very long AI responses (e.g., code explanations, technical documentation)
AiChatWidget(
scrollBehaviorConfig: ScrollBehaviorConfig(
// Prevent auto-scrolling for AI responses, giving user control
autoScrollBehavior: AutoScrollBehavior.onUserMessageOnly,
// Important: Ensure first message of AI response is visible
scrollToFirstResponseMessage: true,
// Slower animation for better user orientation with large content
scrollAnimationDuration: const Duration(milliseconds: 500),
// Ease in-out curve for smoother scrolling experience
scrollAnimationCurve: Curves.easeInOutCubic,
),
config: AiChatConfig(
// Enable markdown for formatted long content
defaultMessageOptions: MessageOptions(
isMarkdown: true,
),
// Optional: Custom styling for code blocks in long responses
markdownConfig: MarkdownConfig(
styleSheet: MarkdownStyleSheet(
code: TextStyle(
backgroundColor: Colors.grey[850],
color: Colors.lightGreenAccent,
fontFamily: 'monospace',
fontSize: 14,
),
codeblockDecoration: BoxDecoration(
color: Colors.grey[850],
borderRadius: BorderRadius.circular(8),
),
),
),
),
)
Constructors
- ScrollBehaviorConfig({AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false, Duration scrollAnimationDuration = const Duration(milliseconds: 300), Curve scrollAnimationCurve = Curves.easeOut})
-
const
Properties
- autoScrollBehavior → AutoScrollBehavior
-
Controls when to automatically scroll to the bottom
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollAnimationCurve → Curve
-
Curve for the scroll animation
final
- scrollAnimationDuration → Duration
-
Duration for the scroll animation
final
- scrollToFirstResponseMessage → bool
-
Whether to scroll to the first message of a response instead of the last message.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
accelerate(
{AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false, Duration duration = const Duration(milliseconds: 350)}) → ScrollBehaviorConfig - Creates a gentle acceleration scrolling configuration Starts slow and speeds up toward the end
-
bouncy(
{AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false, Duration duration = const Duration(milliseconds: 500)}) → ScrollBehaviorConfig - Creates a bouncy scrolling configuration Adds a slight bounce effect at the end of the scroll
-
decelerate(
{AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false, Duration duration = const Duration(milliseconds: 350)}) → ScrollBehaviorConfig - Creates a deceleration scrolling configuration Starts fast and slows down toward the end
-
fast(
{AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false}) → ScrollBehaviorConfig - Creates a fast scrolling configuration with minimal animation For situations where you want quick, direct scrolling
-
smooth(
{AutoScrollBehavior autoScrollBehavior = AutoScrollBehavior.onNewMessage, bool scrollToFirstResponseMessage = false, Duration duration = const Duration(milliseconds: 400)}) → ScrollBehaviorConfig - Creates a smooth scrolling configuration with easeInOut curve Great for a natural, smooth scrolling experience