dropdownfield 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 96

dropdownfield #

Custom Flutter Widget for a customizable dropdown field with auto-complete functionality This widget is meant to be used within a Flutter Form

For a completely working Flutter project demonstrating the usage of dropdownfield, download the code from https://github.com/jagan999/dropdownfieldexample

Installing: #

In your pubspec.yaml, add the following dependency

dependencies:
  dropdownfield: 1.0.0

Example Usage: #

import 'package:dropdownfield/dropdownfield.dart';

    DropDownField(
        value: accountname,
        required: true,
        strict: true,
        labelText: 'Account Name *',
        icon: Icon(Icons.account_balance),
        items: accountNames,
        setter: (dynamic newValue) {
            accountname = newValue;
        }
    ),

Features: #

Can be used for showing drop-down of suggestions for a form field Provides auto-complete functionality - as the user types, shows all suggestions that match part of the typed in text Provides validation of user-typed value against the list of suggestions by default. Can be turned off by setting strict=false Provides ability to do "mandatory" value check if needed Quick clear icon to clear out typed in value Appearance can be customized to match your application theme Clicking dropdown arrow will automatically close the soft keyboard

License: #

This project is licensed under the BSD License - see the LICENSE file for details

[0.0.1] - 12-Feb-2019

  • Can be used for showing drop-down of suggestions for a form field
  • Provides auto-complete functionality - as the user types, shows all suggestions that match part of the typed in text
  • Provides validation of user-typed value against the list of suggestions by default. Can be turned off with a setting
  • Provides ability to do "mandatory" value check if needed
  • Appearance can be customized to match your application theme
  • Clear icon to quickly clear out typed in value
  • Clicking dropdown arrow will automatically close the soft keyboard

[0.0.2] - 13-Feb-2019

  • Only updated the image and README.md

[1.0.0] - 3-Sep-2019

  • Minor code changes
  • Changed revision number to 1.0.0 after many users have used this package

[1.0.1] - 3-Sep-2019

  • Minor code changes
  • Updated image to not show debug banner

[1.0.2] - 13-Sep-2019

  • Moved code repository from BitBucket to github

[1.0.3] - 13-Sep-2019

  • Updated image location

example/main.dart

import 'package:dropdownfield/dropdownfield.dart';
import 'package:flutter/material.dart';
import 'dart:async';

void main() async {
  runApp(MaterialApp(title: 'MyApp', home: ExampleForm()));
}

class ExampleForm extends StatefulWidget {
  ExampleForm();

  @override
  _ExampleFormState createState() => _ExampleFormState();
}

class _ExampleFormState extends State<ExampleForm> {
  // Create a global key that will uniquely identify the Form widget and allow
  // us to validate the form
  final _formKey = GlobalKey<FormState>();
  Map<String, dynamic> formData;
  List<String> cities = [
    'Bangalore',
    'Chennai',
    'New York',
    'Mumbai',
    'Delhi',
    'Tokyo',
  ];
  List<String> countries = [
    'INDIA',
    'USA',
    'JAPAN',
  ];

  _ExampleFormState() {
    formData = {
      'City': 'Bangalore',
      'Country': 'INDIA',
    };
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: buildFutures(),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          switch (snapshot.connectionState) {
            default:
              if (snapshot.hasError) {
                return Text(snapshot.error.toString());
              } else {
                if (snapshot.data != null)
                  return Scaffold(
                      appBar: AppBar(
                        titleSpacing: 5.0,
                        title: Text(
                          'Custom Dropdown Field Example',
                          style: TextStyle(fontSize: 15.0),
                        ),
                        actions: <Widget>[
                          Builder(
                            builder: (BuildContext context) {
                              return IconButton(
                                  icon: const Icon(Icons.check),
                                  iconSize: 20.0,
                                  tooltip: 'Save',
                                  onPressed: () async {
                                    if (_formKey.currentState.validate()) {
                                      _formKey.currentState.save();
                                      _formKey.currentState.save();
                                      showDialog<String>(
                                          context: context,
                                          builder:
                                              (BuildContext dialogContext) =>
                                                  AlertDialog(
                                                    content: Text(
                                                        'Data submitted is \n${formData.toString()}'),
                                                  ));
                                    }
                                  });
                            },
                          )
                        ],
                      ),
                      body: Container(
                        color: Colors.white,
                        constraints: BoxConstraints.expand(),
                        child: Form(
                            key: _formKey,
                            autovalidate: false,
                            child: SingleChildScrollView(
                                child: Column(
                              children: <Widget>[
                                Divider(
                                    height: 10.0,
                                    color: Theme.of(context).primaryColor),
                                DropDownField(
                                    value: formData['City'],
                                    icon: Icon(Icons.location_city),
                                    required: true,
                                    hintText: 'Choose a city',
                                    labelText: 'City *',
                                    items: cities,
                                    strict: false,
                                    setter: (dynamic newValue) {
                                      formData['City'] = newValue;
                                    }),
                                Divider(
                                    height: 10.0,
                                    color: Theme.of(context).primaryColor),
                                DropDownField(
                                    value: formData['Country'],
                                    icon: Icon(Icons.map),
                                    required: false,
                                    hintText: 'Choose a country',
                                    labelText: 'Country',
                                    items: countries,
                                    setter: (dynamic newValue) {
                                      formData['Country'] = newValue;
                                    }),
                              ],
                            ))),
                      ));
                else
                  return LinearProgressIndicator();
              }
          }
        });
  }

  Future<bool> buildFutures() async {
    return true;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dropdownfield: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


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

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/dropdownfield.dart. (-1 points)

Analysis of lib/dropdownfield.dart reported 2 hints:

line 103 col 29: The member 'setState' can only be used within instance members of subclasses of 'package:flutter/src/widgets/framework.dart'.

line 264 col 20: Avoid using unnecessary statements.

Dependencies

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