Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tag Supoort while creating new message #202

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
43 changes: 42 additions & 1 deletion lib/core/widget/add_message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ class _AddMessageWidgetState extends State<AddMessageWidget>
final _commentTextFieldKey = GlobalKey();
final _commentTextEditController = TextEditingController();

List<Widget> tags = <Widget>[
const Text('TagOne'),
const Text('TagTwo'),
const Text('TagThree')
];

final List<bool> _selectedTags = <bool>[false, false, false];

// final ValueChanged<File> _addImageCallback;
File? _selectedImage;
File? _selectedFile;
List<MentionData>? _amityMentionMetadata;

bool istagOneSelected = false;
bool istagTwoSelected = false;

final _focusNode = FocusNode();

final _debouncer = Debouncer(milliseconds: 200);
Expand Down Expand Up @@ -189,6 +200,26 @@ class _AddMessageWidgetState extends State<AddMessageWidget>
icon: const Icon(Icons.camera),
iconSize: 28,
),
ToggleButtons(
direction: Axis.horizontal,
onPressed: (int index) {
// All buttons are selectable.
setState(() {
_selectedTags[index] = !_selectedTags[index];
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
selectedBorderColor: Colors.blue[700],
selectedColor: Colors.white,
fillColor: Colors.blue[200],
color: Colors.blue[400],
constraints: const BoxConstraints(
minHeight: 20.0,
minWidth: 60.0,
),
isSelected: _selectedTags,
children: tags,
),
],
),
Row(
Expand Down Expand Up @@ -256,11 +287,20 @@ class _AddMessageWidgetState extends State<AddMessageWidget>
);
return;
}

List<String>? tagToBeAdded = <String>[];
for (var i = 0; i < _selectedTags.length; i++) {
if (_selectedTags[i]) {
tagToBeAdded.add((tags[i] as Text).data!);
}
}

widget._addCommentCallback.call(
MessageData(
message: text,
image: _selectedImage,
file: _selectedFile,
tags: (tagToBeAdded.isNotEmpty) ? tagToBeAdded : null,
amityMentionMetadata: _amityMentionMetadata,
),
);
Expand Down Expand Up @@ -400,7 +440,8 @@ class MessageData {
File? image;
File? file;
List<MentionData>? amityMentionMetadata;
MessageData({this.message, this.image, this.file, this.amityMentionMetadata});
List<String>? tags;
MessageData({this.message, this.image,this.tags, this.file, this.amityMentionMetadata});
}

class MentionData {
Expand Down
4 changes: 3 additions & 1 deletion lib/presentation/screen/chat/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class _ChatScreenState extends State<ChatScreen> {
if (replyToMessage != null) {
messageBuilder.parentId(replyToMessage!.messageId);
}

if(value.tags != null){
messageBuilder.tags(value.tags!);
}
messageBuilder.send().then((value) {
scrollcontroller.jumpTo(0);
setState(() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_social_sample_app
description: Demonstrates how to use the flutter_application_1 plugin.

version: 1.0.9+9
version: 1.1.4+18

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down
Loading