Previous episode: 24. Introduction
Next episode: 26. Build Out the Filter Page
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
The filter page contains a series of tech domains that the user might be interested in. You'll let the user either show all the domains or just filter down to one particular domain. To help with creating the filter page and keep its code nice and tidy, in this episode, you'll create a filter widget that displays a filter value. The filter page will then consist of a set of these filter widgets. Now, we're going to be using a radio widget to allow the user to make a selection. A radio widget allows the user to make one selection from a series of them. Now, radio widgets don't contain their own state. So we'll use the filter widget to maintain that state. The radio widget comes with two important properties. The first property is just called value. The value is the actual value of the radio widget. So if we have five options, then you might set the value from one to five. The group value makes an association between a collection of radio widgets. This means our collection of five widgets will have different values, but the same group value. To get started, open your project in progress or download the sample app for this episode. We'll be creating a new filter widget. In the filter sub folder, create a new file called filter_widget.dart. Once created, create a new stateless widget. Remember, just type ST and select stateless widget from the dropdown. Name it FilterWidget. Make sure to import the material library. This widget will contain a few properties. First, it will include a value. Remember, this is the backing value for each radio button. Next up, we have to group the value for each radio button as well. The onChange property is notified when the user makes a selection from the radio group. This property will be set to the selection. Finally, our text property represents the filter's name. Now with all of our properties in place, we need to update our constructor. All of these properties with exception of the key will be required. Now for the build method, we will create a radio button and place a label next to it. The text label is just the name of the button. The value, group value and onChange value callback are passed along to the radio widget. And the text is displayed in a text widget. So now we have our filter widget ready to go. In the next episode, you'll use your new filter widget to build out the filter page.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.