autocomplete_textfield 1.5.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 93

autocomplete_textfield

An autocomplete textfield for flutter

Pub Package Can Be Found At

Pub Package

Braking Changes

TextField is set by default to call onSubmitted on a suggestion tap and also to clear the TextField on submit.

These can both be disabled with submitOnSuggestionTap and clearOnSubmit respectively.

Usage

AutoCompleteTextField supports any data type suggestions

new AutoCompleteTextField<YOURDATATYPE>()

The suggestions parameter must have data that matches <YOURDATATYPE>

A global key of type GlobalKey<AutoCompleteTextFieldState<T>> is required so that the clear() method can be called to clear AutoCompleteTextField.

Strings and itemFilter

Filtering is case sensitive so when using strings a common implementation of itemFilter is .
itemFilter: (item, query) { return item.toLowerCase().startsWith(query.toLowerCase()); }

[1.0.0]

Works great published version 1

[1.4.0]

A few bug fixes and more functionality added.

Added textInputAction.

Breaking Changes

TextField is set by default to call onSubmitted on a suggestion tap and also to clear the TextField on submit.

These can both be disabled with submitOnSuggestionTap and clearOnSubmit respectively.

[1.4.1] Added textCapitalization option

[1.5.0]

Added the ability to update suggestions dynamically!

Use updateSuggestions, addSuggestion and removeSuggestion.

[1.5.1]

Oops, spelling error.

example/lib/main.dart

import 'package:autocomplete_textfield/autocomplete_textfield.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Auto Complete TextField Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<String> added = [];
  String currentText = "";
  GlobalKey<AutoCompleteTextFieldState<String>> key = new GlobalKey();

  List<String> suggestions = [
    "Apple",
    "Armidillo",
    "Actual",
    "Actuary",
    "America",
    "Argentina",
    "Australia",
    "Antarctica",
    "Blueberry",
    "Cheese",
    "Danish",
    "Eclair",
    "Fudge",
    "Granola",
    "Hazelnut",
    "Ice Cream",
    "Jely",
    "Kiwi Fruit",
    "Lamb",
    "Macadamia",
    "Nachos",
    "Oatmeal",
    "Palm Oil",
    "Quail",
    "Rabbit",
    "Salad",
    "T-Bone Steak",
    "Urid Dal",
    "Vanilla",
    "Waffles",
    "Yam",
    "Zest"
  ];

  AutoCompleteTextField textField;

  @override
  Widget build(BuildContext context) {
    textField = new AutoCompleteTextField<String>(
        decoration: new InputDecoration(
          hintText: "Search Item",
        ),
        key: key,
        submitOnSuggestionTap: true,
        clearOnSubmit: true,
        suggestions: suggestions,
        textInputAction: TextInputAction.go,
        textChanged: (item) {
          currentText = item;
        },
        textSubmitted: (item) {
          setState(() {
            currentText = item;
            added.add(currentText);
            currentText = "";
          });
        },
        itemBuilder: (context, item) {
          return new Padding(
              padding: EdgeInsets.all(8.0), child: new Text(item));
        },
        itemSorter: (a, b) {
          return a.compareTo(b);
        },
        itemFilter: (item, query) {
          return item.toLowerCase().startsWith(query.toLowerCase());
        });

    Column body = new Column(children: [
      new ListTile(
          title: textField,
          trailing: new IconButton(
              icon: new Icon(Icons.add),
              onPressed: () {
                setState(() {
                  if (currentText != "") {
                    added.add(currentText);
                    textField.clear();
                    currentText = "";
                  }
                });
              }))
    ]);

    body.children.addAll(added.map((item) {
      return new ListTile(title: new Text(item));
    }));

    return new Scaffold(
        appBar: new AppBar(
            title: new Text('Auto Complete TextField Demo'),
            actions: [
              new IconButton(
                  icon: new Icon(Icons.edit),
                  onPressed: () => showDialog(
                      builder: (_) {
                        String text = "";

                        return new AlertDialog(
                            title: new Text("Change Suggestions"),
                            content: new TextField(
                                onChanged: (newText) => text = newText),
                            actions: [
                              new FlatButton(
                                  onPressed: () {
                                    if (text != "") {
                                      suggestions.add(text);
                                      textField.updateSuggestions(suggestions);
                                    }
                                    Navigator.pop(context);
                                  },
                                  child: new Text("Add")),
                            ]);
                      },
                      context: context))
            ]),
        body: body);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  autocomplete_textfield: ^1.5.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:autocomplete_textfield/autocomplete_textfield.dart';
  
Version Uploaded Documentation Archive
1.5.1 Oct 20, 2018 Go to the documentation of autocomplete_textfield 1.5.1 Download autocomplete_textfield 1.5.1 archive
1.5.0 Oct 20, 2018 Go to the documentation of autocomplete_textfield 1.5.0 Download autocomplete_textfield 1.5.0 archive
1.4.1 Sep 30, 2018 Go to the documentation of autocomplete_textfield 1.4.1 Download autocomplete_textfield 1.4.1 archive
1.4.0 Sep 29, 2018 Go to the documentation of autocomplete_textfield 1.4.0 Download autocomplete_textfield 1.4.0 archive
1.3.0 Sep 2, 2018 Go to the documentation of autocomplete_textfield 1.3.0 Download autocomplete_textfield 1.3.0 archive
1.2.1 Aug 6, 2018 Go to the documentation of autocomplete_textfield 1.2.1 Download autocomplete_textfield 1.2.1 archive
1.2.0 Jul 14, 2018 Go to the documentation of autocomplete_textfield 1.2.0 Download autocomplete_textfield 1.2.0 archive
1.1.0 Jul 14, 2018 Go to the documentation of autocomplete_textfield 1.1.0 Download autocomplete_textfield 1.1.0 archive
1.0.0 Jul 14, 2018 Go to the documentation of autocomplete_textfield 1.0.0 Download autocomplete_textfield 1.0.0 archive
0.0.2 Jul 14, 2018 Go to the documentation of autocomplete_textfield 0.0.2 Download autocomplete_textfield 0.0.2 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/autocomplete_textfield.dart. (-0.50 points)

Analysis of lib/autocomplete_textfield.dart reported 1 hint:

line 12 col 7: This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test