flutter material pickers
a flutter package containing commonly used material design picker dialogs. some are new, some wrap existing or built in pickers with a common dialog and access function.
it includes:
- new pickers
- showmaterialscrollpicker:
- allows selection of a string via a slot machine carousel
- showmaterialnumberpicker:
- allows selection of a number via a slot machine carousel
- showmaterialradiopicker:
- allows selection of a single from a radio list
- showmaterialcheckboxpicker:
- allows selection of many values from a checkbox list
- showmaterialselectionpicker:
- allows selection of a single value via an icon label list
- showmaterialscrollpicker:
- convenience pickers
- showmaterialdatepicker:
- allows selection of a date (uses the core date picker)
- showmaterialtimepicker:
- allows selection of a time (uses the core time picker)
- showmaterialcolorpicker:
- allows rgb selection of a color (uses the colorpicker of flutter_colorpicker)
- showmaterialpalettepicker:
- allows material palette selection of a color (uses the materialpicker of flutter_colorpicker)
- showmaterialswatchpicker:
- allows selection of a color from swatches (uses the blockpicker of flutter_colorpicker)
- showmaterialdatepicker:
- dialog
- showmaterialresponsivedialog:
- extends dialog by making it responsive to screen orientation changes
- showmaterialresponsivedialog:
all helpers implement an onchange
handler to return picked option(s).
example usage
empty dialog example
although not a picker, per se, the showmaterialemptypicker helper displays the universal material design dialog wrapper that the pickers appear in. using this directly, however, allows any content to be injected into the content area by passing in a custon widget as the child. this code shows the basic structure of all the helpers:
showmaterialresponsivedialog(
context: context,
child: center(
child: container(
padding: edgeinsets.all(30.0),
child: text("any content here."),
style: textstyle(
fontsize: 20.0,
fontstyle: fontstyle.italic,
),
),
),
);
scroll picker example
var selectedusstate = "connecticut";
list<string> usstates = <string>[
'alabama',
'alaska',
'arizona',
'arkansas',
'california',
'colorado',
'connecticut',
...
];
showmaterialscrollpicker(
context: context,
title: "pick your city",
items: usstates,
selecteditem: selectedusstate,
onchanged: (value) => setstate(() => selectedusstate = value),
);
number picker example
var age = 25;
showmaterialnumberpicker(
context: context,
title: "pick your age",
maxnumber: 100,
minnumber: 14,
selectednumber: age,
onchanged: (value) => setstate(() => age = value),
);
checkbox picker example
list<string> icecreamtoppings = <string>[
'hot fudge',
'sprinkles',
'caramel',
'oreos',
...
];
list<string> selectedicecreamtoppings = <string>[
'hot fudge',
'sprinkles',
];
showmaterialcheckboxpicker(
context: context,
title: "pick your toppings",
items: icecreamtoppings,
selecteditems: selectedicecreamtoppings,
onchanged: (value) => setstate(() => selectedicecreamtoppings = value),
);
radio picker example
var selectedusstate = "connecticut";
list<string> usstates = <string>[
'alabama',
'alaska',
'arizona',
'arkansas',
'california',
'colorado',
'connecticut',
...
];
showmaterialradiopicker(
context: context,
title: "pick your city",
items: model.usstates,
selecteditem: selectedusstate,
onchanged: (value) => setstate(() => selectedusstate = value),
);
selection picker example
string speed = 'ludicrous';
list<string> speedoptions = <string>[
'light',
'ridiculous',
'ludicrous',
'plaid',
];
list<icon> speedicons = <icon>[
icon(icons.sort),
icon(icons.clear_all),
icon(icons.swap_calls),
icon(icons.select_all),
];
showmaterialselectionpicker(
context: context,
title: "starship speed",
items: speedoptions,
selecteditem: speed,
icons: speedicons,
onchanged: (value) => setstate(() => speed = value),
);
time picker example
var time = timeofday.now();
showmaterialtimepicker(
context: context,
selectedtime: time,
onchanged: (value) => setstate(() => time = value),
);
date picker example
var date = datetime.now();
showmaterialdatepicker(
context: context,
selecteddate: date,
onchanged: (value) => setstate(() => date = value),
);
color picker example
color color = colors.red;
showmaterialcolorpicker(
context: context,
selectedcolor: color,
onchanged: (value) => setstate(() => color = value),
);
palette picker example
color palette = colors.green;
showmaterialpalettepicker(
context: context,
selectedcolor: palette,
onchanged: (value) => setstate(() => palette = value),
);
swatch picker example
color swatch = colors.blue;
showmaterialswatchpicker(
context: context,
selectedcolor: swatch,
onchanged: (value) => setstate(() => swatch = value),
);
theming
it is highly recommended you use flutter’s built in theme styling with primaryswatch
to automatically style all controls across your entire application.
themedata(
primaryswatch: colors.indigo,
)
if you desire to override the color for a given control, here is how to customize the theme:
var theme = themedata();
theme = theme.copywith(
primarycolor: colors.green, // background color of the header area
accentcolor: colors.black, // color of selected controls and button bar text
dialogbackgroundcolor: colors.green[300], // background color of the entire dialog
primarytexttheme: theme.primarytexttheme.copywith(
title: theme.primarytexttheme.title.copywith(
color: colors.lightgreen[50], // text color of the header area
),
),
texttheme: theme.texttheme.copywith(
body1: theme.texttheme.body1.copywith(
color: colors.green[900], // text color of dialog text
),
button: theme.texttheme.button.copywith(
color: colors.lightgreen[50], // text color of the action bar buttons
),
),
);
the example app demonstrates switching between light and dark themes globally.
however, if for some reason you want to change colors in an individual dialog, several parameters are exposed to allow this:
showmaterialresponsivedialog(
context: context,
headercolor: colors.green, // background color of the header area
headertextcolor: colors.white, // text fcolor of the header
backgroundcolor: colors.lightgreen, // background color of the entire dialog
buttontextcolor: colors.red, // text color of the action bar buttons
child: text("custom dialog colors"),
);
dependencies
this widget set relies on these external third-party components:
changelog
please see the changelog page to know what’s recently changed.
authors
- jeff jorczak [email protected]
Comments are closed.