simple_autocomplete_formfield 0.2.3

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

SimpleAutocompleteFormField

A Flutter widget that wraps a TextFormField and assists with autocomplete functionality.

example/lib/main.dart

demo.gif

[0.2.3] - September 3, 2018

  • Add .gif of example to README.

[0.2.0] - September 3, 2018

  • Breaking: removed itemParser and added its itemToString and itemFromString as direct parameters.
  • Breaking: containerBuilder has been renamed to suggestionsBuilder.
  • suggestionsHeight has been added since users often want to set it without having to specify the entire suggestionsBuilder.
  • Improved examples.

[0.1.2] - August 14, 2018

  • Fix missing generic type specifier in itemParser usage.

[0.1.1] - July 21, 2018

  • Fix and improve documentation.

[0.1.0] - July 21, 2018

  • Support Dart 2.0.

[0.0.2] - June 13, 2018

  • Added License (MIT).

[0.0.1] - June 13, 2018

  • First release.

example/lib/main.dart

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

final people = <Person>[Person('Alice', '123 Main'), Person('Bob', '456 Main')];
final letters = 'abcdefghijklmnopqrstuvwxyz'.split('');

class _MyHomePageState extends State<MyHomePage> {
  String selectedLetter;
  Person selectedPerson;

  final scaffoldKey = GlobalKey<ScaffoldState>();
  final formKey = GlobalKey<FormState>();
  bool autovalidate = false;

  @override
  Widget build(BuildContext context) => Scaffold(
      key: scaffoldKey,
      appBar: AppBar(title: Text(title)),
      body: Padding(
        padding: EdgeInsets.all(8.0),
        child: Form(
          key: formKey,
          autovalidate: autovalidate,
          child: ListView(children: <Widget>[
            SizedBox(height: 16.0),
            Text('Selected person: "$selectedPerson"'),
            Text('Selected letter: "$selectedLetter"'),
            SizedBox(height: 16.0),
            SimpleAutocompleteFormField<Person>(
              decoration: InputDecoration(
                  labelText: 'Person', border: OutlineInputBorder()),
              suggestionsHeight: 80.0,
              itemBuilder: (context, person) => Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(person.name,
                              style: TextStyle(fontWeight: FontWeight.bold)),
                          Text(person.address)
                        ]),
                  ),
              onSearch: (search) async => people
                  .where((person) =>
                      person.name
                          .toLowerCase()
                          .contains(search.toLowerCase()) ||
                      person.address
                          .toLowerCase()
                          .contains(search.toLowerCase()))
                  .toList(),
              itemFromString: (string) => people.singleWhere(
                  (person) => person.name.toLowerCase() == string.toLowerCase(),
                  orElse: () => null),
              onChanged: (value) => setState(() => selectedPerson = value),
              onSaved: (value) => setState(() => selectedPerson = value),
              validator: (person) => person == null ? 'Invalid person.' : null,
            ),
            SizedBox(height: 16.0),
            SimpleAutocompleteFormField<String>(
              decoration: InputDecoration(
                  labelText: 'Letter', border: OutlineInputBorder()),
              // suggestionsHeight: 200.0,
              maxSuggestions: 10,
              itemBuilder: (context, item) => Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Text(item),
                  ),
              onSearch: (String search) async => search.isEmpty
                  ? letters
                  : letters
                      .where((letter) => search.toLowerCase().contains(letter))
                      .toList(),
              itemFromString: (string) => letters.singleWhere(
                  (letter) => letter == string.toLowerCase(),
                  orElse: () => null),
              onChanged: (value) => setState(() => selectedLetter = value),
              onSaved: (value) => setState(() => selectedLetter = value),
              validator: (letter) => letter == null ? 'Invalid letter.' : null,
            ),
            SizedBox(height: 16.0),
            RaisedButton(
                child: Text('Submit'),
                onPressed: () {
                  if (formKey.currentState.validate()) {
                    formKey.currentState.save();
                    scaffoldKey.currentState
                        .showSnackBar(SnackBar(content: Text('Fields valid!')));
                  } else {
                    scaffoldKey.currentState.showSnackBar(
                        SnackBar(content: Text('Fix errors to continue.')));
                    setState(() => autovalidate = true);
                  }
                })
          ]),
        ),
      ));
}

class Person {
  Person(this.name, this.address);
  final String name, address;
  @override
  String toString() => name;
}

void main() => runApp(MyApp());
const title = 'simple_autocomplete_formfield example';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: title,
      home: MyHomePage(),
    );
  }
}

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

Use this package as a library

1. Depend on it

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


dependencies:
  simple_autocomplete_formfield: ^0.2.3

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:simple_autocomplete_formfield/simple_autocomplete_formfield.dart';
  
Version Uploaded Documentation Archive
0.2.3 Sep 3, 2018 Go to the documentation of simple_autocomplete_formfield 0.2.3 Download simple_autocomplete_formfield 0.2.3 archive
0.2.2 Sep 3, 2018 Go to the documentation of simple_autocomplete_formfield 0.2.2 Download simple_autocomplete_formfield 0.2.2 archive
0.2.1 Sep 3, 2018 Go to the documentation of simple_autocomplete_formfield 0.2.1 Download simple_autocomplete_formfield 0.2.1 archive
0.2.0 Sep 3, 2018 Go to the documentation of simple_autocomplete_formfield 0.2.0 Download simple_autocomplete_formfield 0.2.0 archive
0.1.2 Aug 14, 2018 Go to the documentation of simple_autocomplete_formfield 0.1.2 Download simple_autocomplete_formfield 0.1.2 archive
0.1.1 Jul 21, 2018 Go to the documentation of simple_autocomplete_formfield 0.1.1 Download simple_autocomplete_formfield 0.1.1 archive
0.1.0 Jul 21, 2018 Go to the documentation of simple_autocomplete_formfield 0.1.0 Download simple_autocomplete_formfield 0.1.0 archive
0.0.2 Jun 13, 2018 Go to the documentation of simple_autocomplete_formfield 0.0.2 Download simple_autocomplete_formfield 0.0.2 archive
0.0.1 Jun 13, 2018 Go to the documentation of simple_autocomplete_formfield 0.0.1 Download simple_autocomplete_formfield 0.0.1 archive
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 Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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