FieldSuggestion<T> class

Create highly customizable, simple, and controllable autocomplete fields.

Basic usage example:

FieldSuggestion(
   textController: _textController,
   suggestions: suggestions,
   search: (item, input) {
      return item.toString().contains(input);
   },
   itemBuilder: (context, index) {
      return Card(...);
   },
   ...
)

Network usage example:

FieldSuggestion<String>.network(
  future: future,
  textController: textController,
  builder: (context, snapshot) {
    if (snapshot.connectionState != ConnectionState.done) {
      return Center(child: CircularProgressIndicator());
    }

    final result = snapshot.data ?? [];
    return ListView.builder(
      itemCount: result.length,
      itemBuilder: (context, index) {
        return GestureDetector(
          onTap: () {
            // ... Do something ...
          },
          child: ListTile(title: Text(result[index])),
        );
      },
    );
  },
)

Widget Structure of FieldSuggestion.

╭───────╮ ╭─────────────╮ │ Input │╮ ╭│ Suggestions │ ╰───────╯│ │╰─────────────╯ │ │ │ │ Generated by │ Element search algorithm │ │ ╭──────────╮ ▼ ▼ ╭──▶│ Matchers │─╮ ╭──────────────────╮ │ ╰──────────╯ │ ╭──────────────╮ │ Search Algorithm │──╯ ╰─▶│ Item Builder │ ╰──────────────────╯ ╰──────────────╯ Passes input and suggestion's ... Passes context and element to search function. index of "matcher in suggestions". So, as a result matchers suggestion item widget. fill be filled appropriate to algorithm


Widget Structure of FieldSuggestion.network.

╭───────╮ │ Input │╮ ╰───────╯│ ╭──────────╮ ▼ ╭──▶│ snapshot │─╮ ╭────────╮ │ ╰──────────╯ │ ╭─────────╮ │ future │─╯ ╰─▶│ builder │ ╰────────╯ ╰─────────╯

For mode details about usage refer to:

https://github.com/theiskaa/field_suggestion/wiki

Inheritance

Constructors

FieldSuggestion({Key? key, required Widget itemBuilder(BuildContext, int)?, required TextEditingController textController, required List<T>? suggestions, required bool search(T item, String input)?, Widget separatorBuilder(BuildContext, int)?, BoxController? boxController, BoxStyle? boxStyle, double? maxBoxHeight, InputDecoration? inputDecoration, TextInputType? inputType, FocusNode? focusNode, int? maxLines, TextStyle? inputStyle, FormFieldValidator<String>? validator, double cursorWidth = 2, double? cursorHeight, Radius? cursorRadius, Color? cursorColor, Brightness? keyboardAppearance, ScrollController? scrollController, double spacer = 5.0, int? sizeByItem, EdgeInsets padding = const EdgeInsets.all(12), bool wOpacityAnimation = false, bool wSlideAnimation = false, Duration animationDuration = const Duration(milliseconds: 400), SlideStyle slideStyle = SlideStyle.RTL, Tween<Offset>? slideOffset, Curve slideCurve = Curves.decelerate})
const
FieldSuggestion.network({Key? key, required TextEditingController textController, required Future<List<T>> future(String input)?, required Widget builder(BuildContext, AsyncSnapshot<List<T>>)?, List<T>? initialData, Duration? futureRebuildDuration, void onData(AsyncSnapshot<List<T>>)?, void onError(AsyncSnapshot<List<T>>)?, void onLoad(AsyncSnapshot<List<T>>)?, void onEmptyData(AsyncSnapshot<List<T>>)?, BoxController? boxController, BoxStyle? boxStyle, double? maxBoxHeight, InputDecoration? inputDecoration, TextInputType? inputType, FocusNode? focusNode, int? maxLines, TextStyle? inputStyle, FormFieldValidator<String>? validator, double cursorWidth = 2, double? cursorHeight, Radius? cursorRadius, Color? cursorColor, Brightness? keyboardAppearance, ScrollController? scrollController, double spacer = 5.0, int? sizeByItem, EdgeInsets padding = const EdgeInsets.all(12), bool wOpacityAnimation = false, bool wSlideAnimation = false, Duration animationDuration = const Duration(milliseconds: 400), SlideStyle slideStyle = SlideStyle.RTL, Tween<Offset>? slideOffset, Curve slideCurve = Curves.decelerate})
const

Properties

animationDuration Duration
Duration of suggestion box animation.
final
boxController BoxController?
The controller object for the suggestion box. Can be used to control the suggestion box by opening, closing, and refreshing the content.
final
boxStyle BoxStyle?
The style configuration for the suggestion box.
final
builder → (Widget Function(BuildContext, AsyncSnapshot<List<T>>)?)
The build strategy currently used by this builder.
final
cursorColor Color?
The color of field's cursor.
final
cursorHeight double?
The height(length) of field's cursor.
final
cursorRadius Radius?
The border radius of field's cursor.
final
cursorWidth double
The width(thickness) of field's cursor.
final
focusNode FocusNode?
Focus node of input field.
final
future → (Future<List<T>> Function(String input)?)
The asynchronous computation that this builder is currently connected to, which may be null.
final
futureRebuildDuration Duration?
The rebuild delay for the future computation.
final
hashCode int
The hash code for this object.
no setterinherited
initialData List<T>?
The data that will be used to create the snapshots provided until a non-null future has completed.
final
inputDecoration InputDecoration?
Text input decoration of input field.
final
inputStyle TextStyle?
Text style of input field.
final
inputType TextInputType?
Text input type of input field.
final
itemBuilder → (Widget Function(BuildContext, int)?)
The builder function that creates suggestion widgets for the FieldSuggestion widget.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
keyboardAppearance Brightness?
The appearance of the keyboard. Honored only IOS devices, 'cause Apple is awesome.
final
maxBoxHeight double?
The maximum height for the suggestion box.
final
maxLines int?
Max lines of the input field.
final
onData → (void Function(AsyncSnapshot<List<T>>)?)
A callback that will be called when the future completes successfully with a non-empty result.
final
onEmptyData → (void Function(AsyncSnapshot<List<T>>)?)
A callback that will be called when the future completes successfully with an empty result.
final
onError → (void Function(AsyncSnapshot<List<T>>)?)
A callback that will be called when the future completes with an error.
final
onLoad → (void Function(AsyncSnapshot<List<T>>)?)
A callback that will be called when the future starts running.
final
padding EdgeInsets
Padding of suggestion box's sub widgets.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollController ScrollController?
Scroll controller for the suggestions list.
final
The search algorithm used by the widget.
final
separatorBuilder → (Widget Function(BuildContext, int)?)
The builder function that creates separators for the suggestion list.
final
sizeByItem int?
Sets suggestion box's height by item count.
final
slideCurve Curve
Curve for box slide animation.
final
slideOffset Tween<Offset>?
Tween offset of slide animation.
final
slideStyle SlideStyle
Rotation slide to determine tween offset of slide animation.
final
spacer double
Spacer is the value of size between field and box.
final
suggestions List<T>?
A list of suggested items to be displayed by the widget.
final
textController TextEditingController
Main text editing controller.
final
validator FormFieldValidator<String>?
Field's input validator.
final
wOpacityAnimation bool
Boolean to disable/enable opacity animation of SuggestionBox.
final
wSlideAnimation bool
Boolean to enable/disable slide animation of SuggestionBox.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _FieldSuggestionState
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited