Flyer Chat 💬 Text Stream Message Widget

Pub Version Stars melos

This package provides an opinionated text stream message widget for use with the flutter_chat_ui package. It's designed to display text content that arrives in chunks over time, often seen in interactions with AI assistants or other streaming data sources.

Purpose

This widget is designed specifically to render text stream messages within a flutter_chat_ui implementation. It relies on models and themes provided by flutter_chat_core and is not intended for standalone use outside the Flyer Chat ecosystem.

Installation

Add this package to your pubspec.yaml alongside flutter_chat_ui:

dependencies:
  flutter_chat_ui: ^2.0.0
  flyer_chat_text_stream_message: ^2.0.0

Then run flutter pub get.

Usage

import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:flyer_chat_text_stream_message/flyer_chat_text_stream_message.dart';
import 'your_stream_state_manager.dart'; // Example import

Chat(
    builders: Builders(
        textStreamMessageBuilder: (context, message, index) {
            final streamState = YourStreamStateManager.getState(message.streamId);

            return FlyerChatTextStreamMessage(
                message: message,
                index: index,
                streamState: streamState,
            );
        }
    ),
);

Note: This widget only handles the UI display. You are responsible for:

  1. Creating and managing the actual text stream (fetching data, handling chunks).
  2. Implementing a state management solution (like YourStreamStateManager in the example above) to track the state (Loading, Streaming, Completed, Error) for each stream ID.
  3. Passing the correct StreamState to the FlyerChatTextStreamMessage widget.
  4. Updating your ChatController to replace the TextStreamMessage with a final TextMessage once the stream completes or errors.

For a complete example of how to manage stream state and integrate this widget, see the gemini.dart and gemini_stream_manager.dart files within the example application.

License

Licensed under the MIT License. See the LICENSE file for details.

Libraries

flyer_chat_text_stream_message
Flyer Chat Text Stream Message package. Provides a widget for streamed text messages.