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

card settings

a flutter package for building card settings forms. this includes a library of pre-built form field widgets. the style is a bit like a cross between the cupertino settings screen and material design; the idea is it should be usable and intutive on both ios and android.

card-settings
card settings

this package consists of a cardsettings layout wrapper and a series of form field options including:

  • text fields
    • cardsettingstext – basic text field
    • cardsettingsparagraph – multiline text field with a counter
    • cardsettingsemail – a text field pre-configured for email input
    • cardsettingspassword – a text field pre-configured for passwords
    • cardsettingsphone – a masked phone entry field (us style currently)
  • numeric fields
    • cardsettingsdouble – field for double precision numbers
    • cardsettingsint – field for integer numbers
    • cardsettingscurrency – field for currency entry
    • cardsettingsswitch – field for boolean state
  • pickers
    • cardsettingslistpicker – picker list of arbitrary options
    • cardsettingsnumberpicker – picker list of numbers in a given range
    • cardsettingscolorpicker – rgb color picker
    • cardsettingsdatepicker – material design date picker
    • cardsettingstimepicker – material design time picker
  • selection
    • cardsettingsmultiselect – select from a list of available options
  • informational sections
    • cardsettingsheader – a control to put a header between form sections
    • cardsettingsinstructions – informational read-only text
  • actions
    • cardsettingsbutton – actions buttons for the form

all fields support validate, onchange, onsaved, autovalidate, and visible.

the package also includes these additonal items:

  • cardsettingsfield – the base layout widget. you can use this to build custom fields
  • converters – a set of utility functions to assist in converting data into and out of the fields

simple example

all fields in this package are compatible with the standard flutter form widget. simply wrap the cardsettings control in a form and use it as you normally would with the form functionality.

  string title = "spheria";
  string author = "cody leet";
  string url = "http://www.codyleet.com/spheria"

  final globalkey<formstate> _formkey = globalkey<formstate>();

  @override
  widget build(buildcontext context) {
      body: form(
        key: _formkey,
        child: cardsettings(
          children: <widget>[
            cardsettingsheader(label: 'favorite book'),
            cardsettingstext(
              label: 'title',
              initialvalue: title,
              validator: (value) {
                if (value == null || value.isempty) return 'title is required.';
              },
              onsaved: (value) => title = value,
            ),
            cardsettingstext(
              label: 'url',
              initialvalue: url,
              validator: (value) {
                if (!value.startswith('http:')) return 'must be a valid website.';
              },
              onsaved: (value) => url = value,
            ),
          ],
        ),
      ),
    );
  }

see the full demo example here.

theming

the widgets support the material design theme. this example shows what global theme values to set to determine how the various elements appear.

class myapp extends statelesswidget {

  @override
  widget build(buildcontext context) {
    return new materialapp(
      title: 'card settings example',
      home: new homepage(),
      theme: themedata(
        accentcolor: colors.indigo[400], // used for card headers
        cardcolor: colors.white, // used for field backgrounds
        backgroundcolor: colors.indigo[100], // color outside the card
        primarycolor: colors.teal, // color of page header
        buttoncolor: colors.lightblueaccent[100], // background color of buttons
        texttheme: texttheme(
          button: textstyle(color: colors.deeppurple[900]), // style of button text
          subhead: textstyle(color: colors.deeporange[900]), // style of input text
        ),
      ),
    );
  }
}

or if you want to apply a different theme to the cardsettings hierarchy only, you can wrap it in a theme widget like so:

  theme(
    data: theme.of(context).copywith(
      primarytexttheme: texttheme(
        title: textstyle(color: colors.lightblue[50]), // style for headers
      ),
      inputdecorationtheme: inputdecorationtheme(
        labelstyle: textstyle(color: colors.deeppurple), // style for labels
      ),
    ),
    child: cardsettings(
      ...
    ),
  )

global properties

the cardsettings widget implements a few global settings that all child fields can inherit. currently it supports only label customization.

labels

you can control how the labels are rendered with four properties:

  cardsettings(
    labelalign: textalign.right, // change the label alignment
    labelsuffix: ':', // add an optional tag after the label
    labelpadding: 10.0, // control the spacing between the label and the content
    contentalign: textalign.left, // alignment of the entry widgets
    icon: icon(icons.person), // puts and option icon to the left of the label
    requiredindicator: text('*', style: textstyle(color: colors.red)), // puts an optional indicator to the right of the label
  )

the labelalign and contentalign properties are also available on each field, so you can override the global setting for individual fields.

  cardsettingstext(
    label: 'last name',
    labelalign: textalign.left,
    contentalign: textalign.right,
  )

dynamic visibility

each field implements a visible property that you can use to control the visibility based on the value of other fields. in this example, the switch field controls the visibility of the text field:

  bool _ateout = false;

  cardsettingsswitch(
    label: 'ate out?',
    initialvalue: _ateout,
    onchanged: (value) => setstate(() => _ateout = value),
  ),

  cardsettingstext(
    label: 'restaurant',
    visible: _ateout,
  ),

masking

the cardsettingstext widget has an inputmask property that forces entered text to conform to a given pattern. this is built upon the flutter_masked_text
package and as such masks are formatted with the following characters:

  • 0: accept numbers
  • a: accept letters
  • @: accept numbers and letters
  • *: accept any character

so for example, phone number would be ‘(000) 000-0000’.

note: cardsettingsphone is a convenience widget that is pre-configured to use this pattern.

caution: flutter_masked_text is a controller and as such, you will not be able to use an inputmask and a custom controller at the same time. this might be rectified in the future.

orientation

this suite allows for orientation switching. to configure this, build different layouts depending on the orientation provided by mediaquery.

you might want to have different fields in each layout, or a different field order. so that flutter doesn’t get confused tracking state under this circumstance, you must provide a unique state key for each individual field, using the same key in each layout.

@override
widget build(buildcontext context) {

  final globalkey<formstate> _emailkey = globalkey<formstate>();
  var orientation = mediaquery.of(context).orientation;

  return form
    key: _formkey,(
    child: (orientation == orientation.portraitup)
        ? cardsettings(children: <widget>[
              // portrait layout here
              cardsettingsemail(key: _emailkey)
            ])
        : cardsettings(children: <widget>[
              // landscape layout here
              cardsettingsemail(key: _emailkey)
            ]);
    },
  );
}

you may have multiple fields on the same row in landscape orientation. this normally requires the use of container widgets to provide the layout inside the row. instead, you can use the cardfieldlayout helper widget to streamline this. it will by default make it’s children equally spaced, but you can provide an array of flex values to control the relative sizes.

// equally spaced example
cardsettings(
  children: <widget>[
    cardfieldlayout(children: <widget>[
      cardsettingsemail(),
      cardsettingspassword(),
    ]),
  ],
);
// relative width example
cardsettings(
  children: <widget>[
    cardfieldlayout_fractionallyspaced(
      children: <widget>[
        cardsettingsemail(),
        cardsettingspassword(),
      ],
      flexvalues: [2, 1], // 66% and 33% widths
    ),
  ],
);

custom fields

the cardsettingsfield is the basis of all other fields and can be used to build unique fields outside of this library. its purpose is to govern layout with consistent decorations. the best way to make a custom field is to inherit from formfield<t>, which will manage the state of your field. the cleanest example of this is the cardsettingsswitch widget. all you have to do is provide your custom widgets in the content property.


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

Comments are closed.