Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/src/annotation_editing_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class AnnotationEditingController extends TextEditingController {
}

@override
TextSpan buildTextSpan({BuildContext? context, TextStyle? style, bool? withComposing}) {
TextSpan buildTextSpan(
{BuildContext? context, TextStyle? style, bool? withComposing}) {
var children = <InlineSpan>[];

if (_pattern == null || _pattern == '()') {
Expand Down
158 changes: 86 additions & 72 deletions lib/src/mention_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class FlutterMentions extends StatefulWidget {
this.defaultText,
this.suggestionPosition = SuggestionPosition.Bottom,
this.suggestionListHeight = 300.0,
this.suggestionListWidth = double.infinity,
this.suggestionListPadding = EdgeInsets.zero,
this.onMarkupChanged,
this.onMentionAdd,
this.onSearchChanged,
Expand Down Expand Up @@ -84,6 +86,14 @@ class FlutterMentions extends StatefulWidget {
/// Defaults to `300.0`
final double suggestionListHeight;

/// Max width for the suggestion list
///
/// Defaults to `double.infinity`
final double suggestionListWidth;

/// Suggestion list Padding
final EdgeInsets suggestionListPadding;

/// A Functioned which is triggered when ever the input changes
/// but with the markup of the selected mentions
///
Expand Down Expand Up @@ -412,79 +422,83 @@ class FlutterMentionsState extends State<FlutterMentions> {
: widget.mentions[0];

return Container(
child: PortalEntry(
portalAnchor: widget.suggestionPosition == SuggestionPosition.Bottom
? Alignment.topCenter
: Alignment.bottomCenter,
childAnchor: widget.suggestionPosition == SuggestionPosition.Bottom
? Alignment.bottomCenter
: Alignment.topCenter,
portal: ValueListenableBuilder(
valueListenable: showSuggestions,
builder: (BuildContext context, bool show, Widget? child) {
return show && !widget.hideSuggestionList
? OptionList(
suggestionListHeight: widget.suggestionListHeight,
suggestionBuilder: list.suggestionBuilder,
suggestionListDecoration: widget.suggestionListDecoration,
data: list.data.where((element) {
final ele = element['display'].toLowerCase();
final str = _selectedMention!.str
.toLowerCase()
.replaceAll(RegExp(_pattern), '');

return ele == str ? false : ele.contains(str);
}).toList(),
onTap: (value) {
addMention(value, list);
showSuggestions.value = false;
},
)
: Container();
},
),
child: Row(
children: [
...widget.leading,
Expanded(
child: TextField(
maxLines: widget.maxLines,
minLines: widget.minLines,
maxLength: widget.maxLength,
focusNode: widget.focusNode,
keyboardType: widget.keyboardType,
keyboardAppearance: widget.keyboardAppearance,
textInputAction: widget.textInputAction,
textCapitalization: widget.textCapitalization,
style: widget.style,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
readOnly: widget.readOnly,
showCursor: widget.showCursor,
autofocus: widget.autofocus,
autocorrect: widget.autocorrect,
maxLengthEnforcement: widget.maxLengthEnforcement,
cursorColor: widget.cursorColor,
cursorRadius: widget.cursorRadius,
cursorWidth: widget.cursorWidth,
buildCounter: widget.buildCounter,
autofillHints: widget.autofillHints,
decoration: widget.decoration,
expands: widget.expands,
onEditingComplete: widget.onEditingComplete,
onTap: widget.onTap,
onSubmitted: widget.onSubmitted,
enabled: widget.enabled,
enableInteractiveSelection: widget.enableInteractiveSelection,
enableSuggestions: widget.enableSuggestions,
scrollController: widget.scrollController,
scrollPadding: widget.scrollPadding,
scrollPhysics: widget.scrollPhysics,
controller: controller,
child: Padding(
padding: widget.suggestionListPadding,
child: PortalEntry(
portalAnchor: widget.suggestionPosition == SuggestionPosition.Bottom
? Alignment.topCenter
: Alignment.bottomCenter,
childAnchor: widget.suggestionPosition == SuggestionPosition.Bottom
? Alignment.bottomCenter
: Alignment.topCenter,
portal: ValueListenableBuilder(
valueListenable: showSuggestions,
builder: (BuildContext context, bool show, Widget? child) {
return show && !widget.hideSuggestionList
? OptionList(
suggestionListHeight: widget.suggestionListHeight,
suggestionListWidth: widget.suggestionListWidth,
suggestionBuilder: list.suggestionBuilder,
suggestionListDecoration: widget.suggestionListDecoration,
data: list.data.where((element) {
final ele = element['display'].toLowerCase();
final str = _selectedMention!.str
.toLowerCase()
.replaceAll(RegExp(_pattern), '');

return ele == str ? false : ele.contains(str);
}).toList(),
onTap: (value) {
addMention(value, list);
showSuggestions.value = false;
},
)
: Container();
},
),
child: Row(
children: [
...widget.leading,
Expanded(
child: TextField(
maxLines: widget.maxLines,
minLines: widget.minLines,
maxLength: widget.maxLength,
focusNode: widget.focusNode,
keyboardType: widget.keyboardType,
keyboardAppearance: widget.keyboardAppearance,
textInputAction: widget.textInputAction,
textCapitalization: widget.textCapitalization,
style: widget.style,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
readOnly: widget.readOnly,
showCursor: widget.showCursor,
autofocus: widget.autofocus,
autocorrect: widget.autocorrect,
maxLengthEnforcement: widget.maxLengthEnforcement,
cursorColor: widget.cursorColor,
cursorRadius: widget.cursorRadius,
cursorWidth: widget.cursorWidth,
buildCounter: widget.buildCounter,
autofillHints: widget.autofillHints,
decoration: widget.decoration,
expands: widget.expands,
onEditingComplete: widget.onEditingComplete,
onTap: widget.onTap,
onSubmitted: widget.onSubmitted,
enabled: widget.enabled,
enableInteractiveSelection: widget.enableInteractiveSelection,
enableSuggestions: widget.enableSuggestions,
scrollController: widget.scrollController,
scrollPadding: widget.scrollPadding,
scrollPhysics: widget.scrollPhysics,
controller: controller,
),
),
),
...widget.trailing,
],
...widget.trailing,
],
),
),
),
);
Expand Down
10 changes: 7 additions & 3 deletions lib/src/option_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OptionList extends StatelessWidget {
required this.data,
required this.onTap,
required this.suggestionListHeight,
required this.suggestionListWidth,
this.suggestionBuilder,
this.suggestionListDecoration,
});
Expand All @@ -17,6 +18,8 @@ class OptionList extends StatelessWidget {

final double suggestionListHeight;

final double suggestionListWidth;

final BoxDecoration? suggestionListDecoration;

@override
Expand All @@ -26,9 +29,10 @@ class OptionList extends StatelessWidget {
decoration:
suggestionListDecoration ?? BoxDecoration(color: Colors.white),
constraints: BoxConstraints(
maxHeight: suggestionListHeight,
minHeight: 0,
),
maxHeight: suggestionListHeight,
maxWidth: suggestionListWidth,
minHeight: 0,
minWidth: 0),
child: ListView.builder(
itemCount: data.length,
shrinkWrap: true,
Expand Down
Loading