Skip to content

Commit

Permalink
✨ issue #251 add support of suggestion item type (Scrollable/Newline)
Browse files Browse the repository at this point in the history
  • Loading branch information
apurva780 committed Dec 9, 2024
1 parent 8659c68 commit 2e3820b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [2.3.1]

* **Feat**: [251](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/251) Add
support to provide a type of suggestions item(Scrollable or New Line).
* **Fix**: [282](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/282) Upgrade
version of audio wave forms 1.2.0
* **Fix**: [276](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/276) link preview
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,21 @@ ChatView(
),
```


36. Use `suggestionItemType` to displays a suggestion items in new line and not in scrollable form.


```dart
ChatView(
...
replySuggestionsConfig: ReplySuggestionsConfig(
suggestionItemType: SuggestionItemsType.newLine,
),
...
),
```


## How to use

Check out [blog](https://medium.com/simform-engineering/chatview-a-cutting-edge-chat-ui-solution-7367b1f9d772) for better understanding and basic implementation.
Expand Down
5 changes: 5 additions & 0 deletions lib/src/models/config_models/reply_suggestions_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:chatview/src/models/data_models/suggestion_item_data.dart';
import 'package:flutter/material.dart';

import '../../values/enumeration.dart';
import 'suggestion_item_config.dart';
import 'suggestion_list_config.dart';

Expand All @@ -9,11 +10,15 @@ class ReplySuggestionsConfig {
final SuggestionListConfig? listConfig;
final ValueSetter<SuggestionItemData>? onTap;
final bool autoDismissOnSelection;
final SuggestionItemsType suggestionItemType;
final double spaceBetweenSuggestionItemRow;

const ReplySuggestionsConfig({
this.listConfig,
this.itemConfig,
this.onTap,
this.autoDismissOnSelection = true,
this.suggestionItemType = SuggestionItemsType.scrollable,
this.spaceBetweenSuggestionItemRow = 10,
});
}
9 changes: 9 additions & 0 deletions lib/src/values/enumeration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,12 @@ enum ScrollButtonAlignment {

final Alignment alignment;
}

enum SuggestionItemsType {
scrollable,
multiline;

bool get isScrollType => this == SuggestionItemsType.scrollable;

bool get isMultilineType => this == SuggestionItemsType.multiline;
}
66 changes: 40 additions & 26 deletions lib/src/widgets/suggestions/suggestion_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,53 @@ class _SuggestionListState extends State<SuggestionList>
alignment: const AlignmentDirectional(-1.0, -1.0),
heightFactor: math.max(_controller.value, 0.0),
widthFactor: 1,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: List.generate(
suggestions.length,
(index) {
final suggestion = suggestions[index];
return suggestion.config?.customItemBuilder
?.call(index, suggestion) ??
suggestionsItemConfig?.customItemBuilder
?.call(index, suggestion) ??
Padding(
padding: EdgeInsets.only(
right: index == suggestions.length
? 0
: suggestionsListConfig.itemSeparatorWidth,
),
child: SuggestionItem(
suggestionItemData: suggestion,
),
);
},
),
),
),
child: suggestionsConfig?.suggestionItemType.isScrollType ?? false
? SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _suggestionListWidget(
suggestionsItemConfig,
),
),
)
: Wrap(
runSpacing:
suggestionsConfig?.spaceBetweenSuggestionItemRow ??
10,
alignment: WrapAlignment.end,
children: _suggestionListWidget(suggestionsItemConfig),
),
);
},
),
),
);
}

List<Widget> _suggestionListWidget(
SuggestionItemConfig? suggestionsItemConfig) {
final suggestionsListConfig =
suggestionsConfig?.listConfig ?? const SuggestionListConfig();
return List.generate(
suggestions.length,
(index) {
final suggestion = suggestions[index];
return suggestion.config?.customItemBuilder?.call(index, suggestion) ??
suggestionsItemConfig?.customItemBuilder?.call(index, suggestion) ??
Padding(
padding: EdgeInsets.only(
right: index == suggestions.length
? 0
: suggestionsListConfig.itemSeparatorWidth,
),
child: SuggestionItem(
suggestionItemData: suggestion,
),
);
},
);
}

@override
void deactivate() {
final newSuggestions = chatViewIW?.chatController.newSuggestions;
Expand Down

0 comments on commit 2e3820b

Please sign in to comment.