cobi_flutter_settings 1.0.1
cobi_flutter_settings: ^1.0.1 copied to clipboard

An application settings screen for flutter that persists values via the shared_preferences package

cobi_flutter_settings #

An application settings screen that persists values via the shared_preferences package. This is a material-only version of cobi_flutter_platform_settings

Getting Started #

All widgets come with a property 'settingsKey' which is used to store them in shared_preferences, so you can retrieve the value from anywhere using the same key. The only exceptions from this are SettingsScreen, SettingsGroup and CustomSetting (which is intended to launch navigation routes or to just show some information).

Widgets #

SettingsScreen #

The uppermost settings container. Use this as a starting point.

SettingsScreen (
  title: 'App Settings',
  children: [],
)

SettingsGroup #

A container that groups various settings together

SettingsGroup (
  title: 'First Group',
  children: [],
)

CustomSetting #

A settings widget that takes an onPressed action, useful e.g. to launch navigation routes.

CustomSetting (
  title: 'My Custom Setting',
  subtitle: 'My subtitle',
  onPressed: () => debugPrint('hello world!'),
)

TextSetting #

A widget that shows a textfield

TextSetting<int>(
  settingsKey: 'text-setting',
  title: 'A text setting for integers only',
  keyboardType: TextInputType.number,
  defaultValue: 42000,
  validator: (value) {
    if (value == null || value < 1024 || value > 65536) {
      return 'Integer number between 1024 and 65536 expected';
    }
  },
),

SwitchSetting #

A widget with a two-state switch

SwitchSetting(
  settingsKey: 'switch-setting',
  title: 'This is a switch setting',
  defaultValue: true,
)

CheckboxSetting #

A widget with a checkbox

CheckboxSetting(
  settingsKey: 'checkbox-setting',
  title: 'This is a checkbox setting',
  defaultValue: false,
),

RadioSetting #

This shows a list of radio buttons

RadioSetting<int>(
  settingsKey:  'radio-setting',
  title:  'This is a radio setting',
  items: [
    ListItem<int>(value: 1, caption: 'One'),
    ListItem<int>(value: 2, caption: 'Two'),
    ListItem<int>(value: 3, caption: 'Three'),
    ListItem<int>(value: 4, caption: 'Four'),
    ListItem<int>(value: 5, caption: 'Five'),
  ],
),

RadioModalSetting #

The radio buttons in this one are shown in a dialog

RadioModalSetting<int>(
  settingsKey: 'radio-modal-setting',
  title: 'This is a modal radio setting',
  defaultValue: 5,
  items: [
    ListItem<int>(value: 1, caption: 'One'),
    ListItem<int>(value: 2, caption: 'Two'),
    ListItem<int>(value: 3, caption: 'Three'),
    ListItem<int>(value: 4, caption: 'Four'),
    ListItem<int>(value: 5, caption: 'Five'),
    ListItem<int>(value: 6, caption: 'Six'),
  ],
),

SliderSetting #

You guessed right, a widget with a slider

SliderSetting(
  settingsKey: 'slider-setting',
  title: 'This is a slider setting',
  minValue: 0.0,
  maxValue: 100.0,
  divisions: 100,
  defaultValue: 25.0,
),

You can find more example use cases in the included example app.

Extensibility #

You can define your own widgets by subclassing SettingsWidgetBase<T> and SettingsWidgetBaseState<T, YourSettingsWidgetClass> with T being the type stored via shared_preferences. If you need a data type not supplied by shared_preferences, you can override SettingsWidgetBaseState::persist() and do the serialization yourself.

1
likes
120
pub points
36%
popularity

An application settings screen for flutter that persists values via the shared_preferences package

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on cobi_flutter_settings