0 purchases
cobi flutter settings
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: [],
)
copied to clipboard
SettingsGroup #
A container that groups various settings together
SettingsGroup (
title: 'First Group',
children: [],
)
copied to clipboard
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!'),
)
copied to clipboard
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';
}
},
),
copied to clipboard
ImageSetting #
A widget with an image picker that stores the filename as a string
ImageSetting(
settingsKey: 'image-setting',
title: 'This is an image setting'
),
copied to clipboard
SwitchSetting #
A widget with a two-state switch
SwitchSetting(
settingsKey: 'switch-setting',
title: 'This is a switch setting',
defaultValue: true,
)
copied to clipboard
CheckboxSetting #
A widget with a checkbox
CheckboxSetting(
settingsKey: 'checkbox-setting',
title: 'This is a checkbox setting',
defaultValue: false,
),
copied to clipboard
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'),
],
),
copied to clipboard
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'),
],
),
copied to clipboard
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,
),
copied to clipboard
MultiSelectSetting #
A setting that shows a multi-selection list
MultiSelectSetting<String>(
settingsKey: 'multi-select-setting',
title: "A multi-select setting",
items: [
ListItem(value: "hello", caption: "Hello"),
ListItem(value: "world", caption: "World"),
ListItem(value: "foo", caption: "foo"),
ListItem(value: "bar", caption: "bar"),
]
),
copied to clipboard
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::serialize() and SettingsWidgetBaseState::deserialize() and do the serialization yourself.
Note: Serialization and deserialization behave different since version 2.0.0. See the included example
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.