Flutter Flow: Use the NHTSA API to get vehicle information
![](https://cdn-images-1.medium.com/max/2000/1*5prEDlY7Se8Pq_05oEdcVg.gif)
I’m going to show you how to use the National Highway Traffic Safety Administration API to get the make and model of a car. in the next article, I will demonstrate how to use the VIN of a vehicle to get its information.
Custom development
I get a lot of requests for custom tweaks of Google Maps with Flutter.
I have created a form to capture these requests to better understand everyone’s needs. You can also request custom Flutter Flow development and/or Flutter Flow training.
https://coffeebytez.com/contact-me/
I will focus on the most highly requested items first, which will be available on my substack. I will also post exclusive in-depth tutorials there.
Please subscribe to my substack here:
https://coffeebytez.substack.com/?r=gdmkm&utm_campaign=pub-share-checklist
If you have urgent specific requests, please leave your contact information in the survey.
Adding API Calls
First, on the left side, click the API Calls tab.
![](https://cdn-images-1.medium.com/max/2000/1*S_ApqH0b_23xzDoWcGW96g.png)
Click on the Add button.
Get Car Makes
Now let’s define the car makes API
![](https://cdn-images-1.medium.com/max/2452/1*AvsF6MUHuupOODTsonfoIQ.png)
For the API name I used Get Car Makes
The method type is GET
The API URL is https://vpic.nhtsa.dot.gov/api/vehicles/GetMakesForVehicleType/car?format=json
If you click on the Response & Test tab, click Test API Call, you will see the response. Notice the results have MakeId, MakeName, etc.
![](https://cdn-images-1.medium.com/max/2432/1*3XIUHr24UTpu3wZGpXOoPA.png)
Get Car Models
There are two ways to get the make from the model, by using the **MakeId (Get Models for Make) **or MakeName (Get Models for Make) from the make response.
I believe using MakeId would be a better option, because they may change the name anytime. For this simple example, I’m using MakeName.
![](https://cdn-images-1.medium.com/max/2424/1*WszzB8RrOysUSfpOKoBebA.png)
I gave it the name Get Models For Make
The method type is GET
The API URL is https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMake/[make]?format=json
If you want to use MakeId the URL is https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/[make]?format=json
Notice I have make in square brackets. In this API we need to pass it as a path parameter.
Go to the Variables tab and add a String parameter
![](https://cdn-images-1.medium.com/max/2380/1*r3vGe9Gxg3m1v29rBhpgRA.png)
If you click on the Response & Test tab and click Test API Call, you will see the response. Notice the results have Make_Id, Make_Name, Model_Name, etc.
![](https://cdn-images-1.medium.com/max/2488/1*08jj4EkWZi11nii7bnFKew.png)
Create data types
For this example, I have created data types for the API responses, by going to the Data Types tab to the left.
![](https://cdn-images-1.medium.com/max/2276/1*-2QBjyyNZmaxmecS75z7uA.png)
![](https://cdn-images-1.medium.com/max/2282/1*onybX5Qa1coyAOyLCji1_A.png)
Get Vehicle Make and Models UI
Now let’s create the UI for getting a vehicle’s make and models. For this example, I have two dropdown widgets.
I’m going to populate the first one once the screen is loaded. After the user chooses a make from the options, I will make a call to get the models for that vehicle. After the user chooses a model, it will populate the text field below it.
![](https://cdn-images-1.medium.com/max/2028/1*QkVhRDF3Tf5neTwMBULwpw.png)
I have created three state variables on the top-level widget.
![](https://cdn-images-1.medium.com/max/2000/1*KHZ-xcphu3tZUmRczwyc2A.png)
Makes and models are types of list of Data Types we created earlier
![](https://cdn-images-1.medium.com/max/2000/1*ZRdksNk43UIjysjzy2CTWg.png)
I have a z instead of a s at the end of the models state field. I believe I can’t reuse models because the data type uses it.
![](https://cdn-images-1.medium.com/max/2000/1*5Hs6nauVvPMtEAFv7oVRoA.png)
The makeAndModel state field is a nullable String
![](https://cdn-images-1.medium.com/max/2000/1*NdpWv-V2WfEIHjWb7bSxvw.png)
Querying vehicle makes
On the top-level widget, I am also creating an action to make the API Call to get the car makes.
![](https://cdn-images-1.medium.com/max/2000/1*gLSnqviK7DAIaFHIUy4BmQ.png)
For the Action Output Variable Name, I left it to what Flutter Flow generated.
![](https://cdn-images-1.medium.com/max/2000/1*aPfKn1x_hwhTsmjGVh6gkA.png)
If the API result was a success I update the page state by setting Results field to the makes page state
![](https://cdn-images-1.medium.com/max/2000/1*6-9igp0L4uDOwJPXW3Hs2w.png)
Showing make results in a dropdown
![](https://cdn-images-1.medium.com/max/2078/1*8083vNkKM_XuPu5I2nfqOw.png)
To show the list of makes in the first dropdown, click on the dropdown, and find Define Options.
Click the orange settings button, choose the makes page state variable, and choose MakeName as the value to show. In this example, I decided to sort them by the MakeName.
Making the Get Models API call when choosing a vehicle make
For the action of On Selected, on the makes dropdown, let’s create an action.
![](https://cdn-images-1.medium.com/max/2000/1*rGPGYV2hIs4XhRAScPN4vg.png)
The first action calls the model API using the make value from the make dropdown. I keep the default generated Action Output Variable Name, but remember it so we can use it in the next steps.
![](https://cdn-images-1.medium.com/max/2000/1*QmMbPubQ7QbJB8hP-C-tpw.png)
In the success action, I am setting the action output to the modelz page state.
![](https://cdn-images-1.medium.com/max/2000/1*XHwaSRYNrvyVAmlj6bMDKQ.png)
Showing the models in the dropdown
Showing the models in the models dropdown to what we did previously for the makes dropdown.
Use the page state variable modelz, choose the Model_Name as the value to show, and sort the items by Model_Name.
![](https://cdn-images-1.medium.com/max/2094/1*-Lgq__Ty2jSD7bSJgD66nw.png)
We will also create an action when a model is selected. It will set the String variable to the values of the dropdowns.
![](https://cdn-images-1.medium.com/max/2000/1*P2NWJDbD70F3aFBPh2-ZKg.png)
Your working example should look similar to this:
![](https://cdn-images-1.medium.com/max/2000/1*5prEDlY7Se8Pq_05oEdcVg.gif)