Welcome back!
We created this feature TextField composable containing text and textfield.
Now let's use this composable inside car features four.
So here under the text Car specifications we're gonna add the text fields.
So let's start by the first one for the cylinders.
So feature text field set the label to cylinders.
The value car features dot cylinders dot to string and set the on value changed.
You can create like this as a Gemini suggests for us.
But I can use a lambda expression which is the value here and set on features.
Changed car features.
Dot copy the number of cylinders equals to value the new value dot two float or null.
So let me make it like a new value in order to distinguish it.
New value equals to new value, dot to float or make it as default as four cylinders.
And the placeholder here would be four, 6 or 8.
Let me explain this one time in order to because we're going to use it in the next parameters.
So here on value change a callback that gets triggered when a value changed user selects from a drop
down menu a slider, or actually, if the user enters any number in the text field, the new value,
the new value that was selected or changed or entered, the on features and on features changed.
This is a callback function with the updated car features.
The value to float or null safely converts the value to a float.
Returns null If conversion fails and this is the Elvis operator provides a default value or of a for
F if the conversion result is null.
So here we are trying to convert the user input, since the text field will the.
The result of text field is a string, we need to convert it to an integer or a float.
And here we're going to get the cylinders in a float.
So we can't get cylinders in a string uh, a string.
Because if we go back to car features the cylinders is of type float.
If the user enters any data it would be of type string.
And here the value would be in type string.
Now we need to convert the value to a new value.
But this time the new value is of type float okay.
So we're going to copy the newvalue dot to float.
We are converting it to a float.
So this is just converting the data, the input that entered by the user as a string to a float.
If it is converted successfully, go and and preserve the result.
If not, go and return for f as a default value.
Okay, this is very simple guys.
We talked about it in the in the previous sections and we see it in many videos.
But I should mention it here in order to make everything clear this is the first text field.
Let's continue with the other parameters.
So here feature text fields text field.
Set the label displacement cc value displacement dot to string on value changed the similar to what
we've done here.
We need to do here on features changed.
Set the car features dot copy displacement new value to float or set a default value to 150.
Okay, it's very simple.
Placeholder 100, 150, 200, and so on.
This is the second text field.
The third text field is about the horsepower.
So label horsepower on value changed car features dot horsepower dot string.
We are getting them from this data class.
The horsepower.
And also we're going to set the on value changed new value on features changed.
Similar to what we've done before car features.
We are converting the entered value of the horsepower into a float.
If the conversion is successfully, go and set that to a new value.
If not, go and make it as default as 100.
Uh F, which is for the horsepower.
Okay, this is the logic.
And this is how we keep our application safe from any errors.
I'll continue with other features like the weight, the other feature acceleration 0 to 60.
Get the acceleration from car features, set the on value changed and make it 15 F, which is the default
value.
Set the placeholder to five, 10 or 15, and so on.
You can make it, uh, for example 515.
So okay.
Now the other feature is the model year value changed new value set.
The default is to 76 f.
And here specify the placeholder.
This is the feature text field set.
The model year range is from 70 to 82 okay this is good.
Now we're going to create a text for the origin material theme dot typography.
I'm gonna create a drop down menu or a selection, a selection, a bunch of buttons you can select from
them, or a drop down menu for the origin.
So we have American, European and Japanese.
We're going to create uh, we're going to allow the user to select one of them.
I'm not going to allow it to allow the user to enter one, 2 or 3 because he didn't know.
Or you can make like hints like one represents American, two represents, uh, European, three represents
Japanese.
But for making our application more, more professional, we're going to create a drop down menu.
Or you can make a selection of radio buttons or a group of buttons to allow the user to select one of
those artisans.
Okay.
So don't worry.
Please follow me and I'll lecture everything.
Modifier modifier dot padding ADP from top and bottom.