Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

a flutter package that provides a dropdown form field using a dropdown button inside a form field.

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),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top