CupertinoPicker — All Cupertino Widgets
In this series, we look at the whole Cupertino package of Flutter. You will get to know every widget, essential classes, and much more in this series. All the articles will be less than 2 minutes long, so you can read them every time :) In addition to that, they will be effortless to understand, following the motto
Make everything as simple as possible, but not simpler. ~ Albert Einstein
If you want to check out the other articles of this series, check out this list. Let’s get started!
Happy reading!
CupertinoPicker
The CupertinoPicker
is an iOS-styled picker. The user can select between multiple options on a wheel-like widget.
First, we want to set our properties. For this, there is the children
property. But if you have many options to select, this can get a bit untidy. A better approach would be if you have a List<String> and then use List<Widget>.generate(myList.length, (int index) {//Return your widgets}
.
After the user selected his value, you can call some things with onSelectedItemChanged
. But be aware: You don’t get a string
or something similar as an output, but an int
.
Okay, but now we want to style or picker. First, we take a look at magnification. First, there is the useMagnifier
property, that specifies, whether to use magnification on the center widget (the currently selected item) or not. If you use it, then you can specify the magnification with magnification
property of type double
.
squeeze
specifies the compactness of the widgets on the wheel, and you can set the backgroundColor
too.
These were the most important properties, but of course, there are some more. Take a look at them here.
But for now, let’s take a look at an example:
Conclusion & Further reading
In this article, you have learned how to use the CupertinoPicker.
Did you know that there are great packages that enhance your development enormously? For example Freezed, Isar, or Flutter Hooks. If you want to learn about these great packages, I have entire tutorials about them. Check them out here.
In the following few articles, I will introduce more Cupertino widgets, essential classes, and more stuff. If you don’t want to miss this, I recommend you follow me!
Thanks for reading, have a nice day!