A Flutter package that provides a dropdown form field using a dropdown button inside a form field.

Overview

Donate - Buy Me A Coffee

Dropdown form field

A dropdown form field using a dropdown button inside a form field.

Demo

Features

  • Can be used as regular form field.
  • Simple to implement.
  • Simple and intuitive to use in the app.
  • Provides validation of data.
  • Provides requirement of the field.
  • Follows the app theme and colors.

Example

import 'package:dropdown_formfield/dropdown_formfield.dart';

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

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

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

class _MyHomePageState extends State<MyHomePage> {
  String _myActivity;
  String _myActivityResult;
  final formKey = new GlobalKey<FormState>();

  @override
  void initState() {
    super.initState();
    _myActivity = '';
    _myActivityResult = '';
  }

  _saveForm() {
    var form = formKey.currentState;
    if (form.validate()) {
      form.save();
      setState(() {
        _myActivityResult = _myActivity;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Dropdown Formfield Example'),
      ),
      body: Center(
        child: Form(
          key: formKey,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: EdgeInsets.all(16),
                child: DropDownFormField(
                  titleText: 'My workout',
                  hintText: 'Please choose one',
                  value: _myActivity,
                  onSaved: (value) {
                    setState(() {
                      _myActivity = value;
                    });
                  },
                  onChanged: (value) {
                    setState(() {
                      _myActivity = value;
                    });
                  },
                  dataSource: [
                    {
                      "display": "Running",
                      "value": "Running",
                    },
                    {
                      "display": "Climbing",
                      "value": "Climbing",
                    },
                    {
                      "display": "Walking",
                      "value": "Walking",
                    },
                    {
                      "display": "Swimming",
                      "value": "Swimming",
                    },
                    {
                      "display": "Soccer Practice",
                      "value": "Soccer Practice",
                    },
                    {
                      "display": "Baseball Practice",
                      "value": "Baseball Practice",
                    },
                    {
                      "display": "Football Practice",
                      "value": "Football Practice",
                    },
                  ],
                  textField: 'display',
                  valueField: 'value',
                ),
              ),
              Container(
                padding: EdgeInsets.all(8),
                child: RaisedButton(
                  child: Text('Save'),
                  onPressed: _saveForm,
                ),
              ),
              Container(
                padding: EdgeInsets.all(16),
                child: Text(_myActivityResult),
              )
            ],
          ),
        ),
      ),
    );
  }
}

License

This project is licensed under the BSD License. See the LICENSE file for details.

Comments
  • inputdecoration and focusnode added along with other ui customization options

    inputdecoration and focusnode added along with other ui customization options

    now people can have more control over how dropdown_formfield looks

    1. added UI customization helper classes
    2. added input decoration and focus node
    3. other cool UI options
    opened by shivanshtalwar0 2
  • added support for InputDecoration Fixed #4

    added support for InputDecoration Fixed #4

    although the way of providing label text to DropDownFormField is changed. it provides more flexibility while designing the user interface. the user interface of dropdown can be changed either by providing your own InputDecoration or by providing premade InputDecoration like :

    1. RoundedDropDownDecoration
    2. OutlinedDropDownDecoration
    opened by shivanshtalwar0 0
  • onSaved value is null when no onChanged event is triggered even when value is set

    onSaved value is null when no onChanged event is triggered even when value is set

    Nexus 5X API 29 x86 (android-x86 emulator) Flutter 1.9.1 + hotfix.4

    Only line changed in code example is: _myActivity = 'Running'; from _myActivity = '';

    When putting a breakpoint at onSaved, and then pressing on the save button without selecting anything then value = null. Yet, the dropdown shows the right text.

    Problem occured to me when updating a form, inserting initial values, and then clicking on save without changing the initial values. In the mean time, I just check for when it is null, and don't update that field.

    import 'package:dropdown_formfield/dropdown_formfield.dart';
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      String _myActivity;
      String _myActivityResult;
      final formKey = new GlobalKey<FormState>();
    
      @override
      void initState() {
        super.initState();
        _myActivity = 'Running';
        _myActivityResult = '';
      }
    
      _saveForm() {
        var form = formKey.currentState;
        if (form.validate()) {
          form.save();
          setState(() {
            _myActivityResult = _myActivity;
          });
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Dropdown Formfield Example'),
          ),
          body: Center(
            child: Form(
              key: formKey,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.all(16),
                    child: DropDownFormField(
                      titleText: 'My workout',
                      hintText: 'Please choose one',
                      value: _myActivity,
                      onSaved: (value) {
                        setState(() {
                          _myActivity = value;
                        });
                      },
                      onChanged: (value) {
                        setState(() {
                          _myActivity = value;
                        });
                      },
                      dataSource: [
                        {
                          "display": "Running",
                          "value": "Running",
                        },
                        {
                          "display": "Climbing",
                          "value": "Climbing",
                        },
                        {
                          "display": "Walking",
                          "value": "Walking",
                        },
                        {
                          "display": "Swimming",
                          "value": "Swimming",
                        },
                        {
                          "display": "Soccer Practice",
                          "value": "Soccer Practice",
                        },
                        {
                          "display": "Baseball Practice",
                          "value": "Baseball Practice",
                        },
                        {
                          "display": "Football Practice",
                          "value": "Football Practice",
                        },
                      ],
                      textField: 'display',
                      valueField: 'value',
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.all(8),
                    child: RaisedButton(
                      child: Text('Save'),
                      onPressed: _saveForm,
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.all(16),
                    child: Text(_myActivityResult),
                  )
                ],
              ),
            ),
          ),
        );
      }
    }
    
    opened by yschermer 0
  • Null safe library

    Null safe library

    I am trying to use your beautiful package but get this error "The library 'package:dropdown_formfield/dropdown_formfield.dart' is legacy, and shouldn't be imported into a null safe library. (Documentation)" Could you please advice?

    opened by AlimFreight 0
  • Migrate to Null Safety

    Migrate to Null Safety

    #20 Migrate to Null Safety By testing all features and also replace deprecated attribute autovalidate to autovalidateMode and set the default value to disable.

    To Migrate to null safety used the dart migrate tool and review code changes. dart migrate

    opened by samiraj99 2
  • How to set font size of text label and hint ?

    How to set font size of text label and hint ?

    `library dropdown_formfield;

    import 'package:flutter/material.dart';

    class DropDownFormField extends FormField { final String titleText; final String hintText; final bool required; final String errorText; final dynamic value; final List dataSource; final String textField; final String valueField; final Function onChanged; final bool filled; final EdgeInsets contentPadding;

    DropDownFormField( {FormFieldSetter onSaved, FormFieldValidator validator, bool autovalidate = false, this.titleText = 'Title', this.hintText = 'Select one option', this.required = false, this.errorText = 'Please select one option', this.value, this.dataSource, this.textField, this.valueField, this.onChanged, this.filled = true, this.contentPadding = const EdgeInsets.fromLTRB(12, 12, 8, 0)}) : super( onSaved: onSaved, validator: validator, autovalidate: autovalidate, initialValue: value == '' ? null : value, builder: (FormFieldState state) { return Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ InputDecorator(

                    decoration: InputDecoration(
                      contentPadding: contentPadding,
                      labelText: titleText,
                      filled: filled,
                    ),
                    child: DropdownButtonHideUnderline(
                      child: DropdownButton<dynamic>(
                        isExpanded: true,
                        hint: Text(
                          hintText,
                          style: TextStyle(color: Colors.grey.shade500),
                        ),
                        value: value == '' ? null : value,
                        onChanged: (dynamic newValue) {
                          state.didChange(newValue);
                          onChanged(newValue);
                        },
                        items: dataSource.map((item) {
                          return DropdownMenuItem<dynamic>(
                            value: item[valueField],
                            child: Text(item[textField],
                                overflow: TextOverflow.ellipsis),
                          );
                        }).toList(),
                      ),
                    ),
                  ),
                  SizedBox(height: state.hasError ? 5.0 : 0.0),
                  Text(
                    state.hasError ? state.errorText : '',
                    style: TextStyle(
                        color: Colors.redAccent.shade700,
                        fontSize: state.hasError ? 12.0 : 0.0),
                  ),
                ],
              ),
            );
          },
        );
    

    } `

    opened by vpaul9678 0
Owner
Carlos Eugenio Torres
Principal Software Engineer
Carlos Eugenio Torres
Masked text field - A flutter package for masked text field for formet your text and good UI

Masked Text Field Masked Text Field Features A package for masked text field for

Alok Dubey 7 Sep 4, 2022
A Flutter package with an advanced dropdown Button which let you give different design on DropdownButton

Use decorated_dropdown button to add DropdownButton with decoration properties l

Hari Prasad Chaudhary 1 Dec 17, 2021
Custom dropdown widget allows to add highly customizable widget in your projects with proper open and close animations and also comes with form required validation.

Custom Dropdown Custom Dropdown package lets you add customizable animated dropdown widget. Features Lots of properties to use and customize dropdown

Abdullah Chauhan 22 Dec 29, 2022
A flutter package that provides multiple states for a button with endless customizability.

multi_state_button A package which provides multiple states for a button with endless customizability. Getting Started Add dependency dependencies:

null 4 Apr 11, 2022
Swipeable button view - Create Ripple Animated Pages With Swipeable Button View

swipeable_button_view You can create ripple animated pages with swipeable_button

cemreonur 3 Apr 22, 2022
Jannis 0 Jan 29, 2022
Boris Gautier 1 Jan 31, 2022
Working proof of the Go (golang) server running inside Flutter

flap Working proof of the Go server running inside Flutter Video in action Prerequisites Flutter >2.0 Go >1.16 Build Go server cd go macOS: make maco

Err 28 Dec 17, 2022
A flutter plugin to draw the coordinates on the widget and as well as to find the given point is inside a list of coordinates or not.

Draw On A flutter plugin to draw the coordinates on widget and as well as to find the given point is inside a list of coordinates or not. For Draw on

Sivaramsiva10 4 Apr 5, 2022
A Learning Management System Solutions Developed from Scratch inside Orange Digital Center Labs By ODC-Flutter WorkForce.

A Learning Management System Solutions Developed from Scratch inside Orange Digital Center Labs By ODC-Flutter WorkForce.

Orange Digital Center Egypt - Coding School 5 May 9, 2022
Allows communication between your bot and the Web App built in Flutter displayed inside Telegram.

tele_web_app It enables communication between your bot and the Flutter-embedded Web App displayed inside Telegram by making use of interoperability be

Yeikel Uriarte Arteaga 16 Dec 8, 2022
Allows tags to be entered inside textfield

textfield_tags This is a widget that allows your users to create tags by entering the tag's name inside of textfield and make the tags appear in the t

Eyoel Defare 75 Nov 2, 2022
Iridium-reader-widget - Plug and play reader widget allowing to easily integrate an Iridium viewer inside any app

Plug and play reader widget allowing to easily integrate an Iridium viewer insid

Mantano 15 Dec 31, 2022
Makes it possible to safely execute and retry a Future inside a StatelessWidget

futuristic Makes it possible to safely execute and retry a Future inside a StatelessWidget. See the Mainstream package for a similar API for working w

Martin Rybak 28 Sep 15, 2022
A dart library to check if given point(s) are present inside polygon or not.

poly A library for checking if given point(s) is present inside Polygon or not. Contents Installation Examples Note: Instead of casting, use toListNum

Sacchi 9 Feb 25, 2022
Flutter form fields designed to take much of the burden of form-related coding off the programmer's back — masks, validations, keyboard type, etc.

well_formed Contents Overview Getting Started Demo application References Overview Well-Formed Widget Fields - Well-Formed - is a collection of Flutte

Dartoos 7 Nov 2, 2022
Form builder image picker - Form builder image picker for flutter

form_builder_image_picker Field for picking image(s) from Gallery or Camera for

Ferri Sutanto 0 Jan 28, 2022
User auth form - Signup and signin user auth form with ability to stay signed in and have an option to signout.

user_auth_form SIgnup and signin user authentification form Getting Started This project is a starting point for a Flutter application. A few resource

null 0 Jan 6, 2022
🔥🚀 Flutter package to create Pin code input text field with every pixel customization possibility 🎨 with beautiful animations

Flutter PinPut From Tornike ?? ?? Flutter package to create Pin code input (OTP) text field with every pixel customization possibility ?? and beautifu

Tornike 451 Jan 2, 2023