@@ -846,14 +846,14 @@ ChatView(
846846ChatView(
847847 // ...
848848 featureActiveConfig: FeatureActiveConfig(
849- enableSwipeToReply: true,
850- enableSwipeToSeeTime: false,
851- enablePagination: true,
852- enableOtherUserName: false,
853- lastSeenAgoBuilderVisibility: false,
854- receiptsBuilderVisibility: false,
855- enableTextSelection: true,
856- enableEditMessage : true, // Enable the Edit Message feature (default: true )
849+ enableSwipeToReply: true, // Enable swipe to reply (default: true)
850+ enableSwipeToSeeTime: false, // Enable swipe to see message time (default: true)
851+ enablePagination: true, // Enable pagination (default: false)
852+ enableOtherUserName: false, // Show other user's name above bubble (default: true)
853+ lastSeenAgoBuilderVisibility: false, // Show last seen ago label (default: true)
854+ receiptsBuilderVisibility: false, // Show message receipts (default: true)
855+ enableTextSelection: true, // Enable text selection in bubbles (default: false)
856+ enableMessageEditing : true, // Enable the edit message feature (default: false )
857857 ),
858858 // ...
859859)
@@ -869,92 +869,19 @@ ChatView supports editing previously sent text messages, similar to WhatsApp and
8698692 . Tap ** Edit** in the reply pop-up.
8708703 . The original text is pre-filled into the input field with an * Editing* indicator above it.
8718714 . Modify the text and press Send.
872- 5 . Your ` onEditTap ` callback is called with the ** original ` Message ` ** and the ** new text ** .
873- 6 . Messages that have been edited display a subtle * Edited * label below the bubble.
872+ 5 . Your ` onEditTap ` callback is called with the ** original ` Message ` ** ( ` oldMessage ` ) and the ** updated ` Message ` ** ( ` newMessage ` ) .
873+ 6 . Messages that have been edited display a subtle _ Edited _ label below the bubble.
874874
875875### Basic Integration
876876
877877``` dart
878878ChatView(
879879 // ...
880- onEditTap: (Message originalMessage, String newText) {
881- // Update the message in your data source / backend.
882- // Set `updateAt` on the message to trigger the "Edited" label in the UI.
883- final updatedMessage = Message(
884- id: originalMessage.id,
885- message: newText,
886- createdAt: originalMessage.createdAt,
887- sentBy: originalMessage.sentBy,
888- updateAt: DateTime.now(), // marks the message as edited
889- replyMessage: originalMessage.replyMessage,
890- messageType: originalMessage.messageType,
891- );
892-
893- chatController.updateMessage(updatedMessage); // depends on your controller API
894- },
895- replyPopupConfig: ReplyPopupConfiguration(
896- // Optional: react to the edit tap in the popup before the editing UI opens.
897- onEditTap: (message) => debugPrint('Editing: ${message.id}'),
898- ),
899- // ...
900- )
901- ```
902-
903- ### Disabling the Feature
904-
905- ``` dart
906- ChatView(
907- featureActiveConfig: const FeatureActiveConfig(
908- enableEditMessage: false, // hides the Edit button entirely
909- ),
910- )
911- ```
912-
913- ### Localization
914-
915- The edit-related strings can be customized via ` ChatViewLocale ` :
916-
917- ``` dart
918- PackageStrings.addLocaleObject(
919- 'es',
920- const ChatViewLocale(
921- // ... all other required fields ...
922- edit: 'Editar',
923- edited: 'Editado',
924- editing: 'Editando',
925- ),
926- );
927- PackageStrings.setLocale('es');
928- ```
929-
930- ### Static Helper
931-
932- Use ` ChatView.getEditingMessage(context) ` to read the message currently being edited
933- from a widget that is a descendant of ` ChatView ` :
934-
935- ``` dart
936- final editingMsg = ChatView.getEditingMessage(context);
937- if (editingMsg != null) {
938- // User is in edit mode for editingMsg.
939- }
940- ```
941-
942- ### Customizing the Edit Indicator Label
943-
944- When a user enters edit mode, an indicator bar is displayed above the text field showing a label
945- (default: locale-resolved ` "Editing" ` ). You can override this label via ` SendMessageConfiguration ` :
946-
947- ``` dart
948- ChatView(
949- // ...
950- sendMessageConfig: SendMessageConfiguration(
951- /// The label shown in the editing indicator bar above the text field
952- /// when the user is editing an existing message.
953- ///
954- /// If omitted, falls back to the locale-resolved value of
955- /// `PackageStrings.currentLocale.editing` (e.g. `"Editing"`).
956- editLabel: 'Editing message',
957- ),
880+ // updatedMessage is a copy of oldMessage with the new text already applied.
881+ // You have access to both objects so you can do further transformations —
882+ // for example, update the timestamp, change the message type, or sync with a backend.
883+ onEditTap: (message, updatedMessage) =>
884+ _chatController.updateMessage(messageId: message.id, newMessage: updatedMessage),
958885 // ...
959886)
960887```
0 commit comments