If you're seeking to learn how to use FlutterFlow by building exercises, it's important to know that FlutterFlow is a low-code visual interface tool designed to make it easier to build Flutter apps. As of my knowledge cutoff in March 2023, FlutterFlow provides a simpler interface to create Flutter apps without extensive coding, so here are two exercises you can try to get started with creating and linking forms with data from Firestore and custom APIs.
Exercise 1: Basic Form Submission to Firestore
Objective:
Create a simple app with a form that allows the user to submit their name to Firestore.
Steps:
-
Firestore Setup:
- Before you start with FlutterFlow, make sure you have a Firestore database set up in your Firebase project.
- Create a collection called
users.
-
FlutterFlow Project:
- Create a new FlutterFlow project.
- Drag a
TextField widget from the widget panel to the canvas.
- Label it as "Name".
- Set the variable linked to this TextField to
userName.
-
Firestore Integration:
- Drag a
Button widget onto the canvas below the TextField.
- Inside the button's
onPressed properties, choose the Firestore integration.
- Select the action to "Create Document" within the
users collection.
- Map the field (e.g.,
name) to the userName variable.
-
Run Your FlutterFlow App:
- Save your flow and run the app in the preview or on a physical device.
- Enter a name into the text field and press the button.
- Check your Firestore database to see if the new document with the entered name is created.
Exercise 2: Fetch Data from a Custom API
Objective:
Create an app that fetches data from a custom API and displays it on the screen.
Assumptions:
You have access to a simple API endpoint that returns a JSON object, such as a random user information. For example, https://randomuser.me/api/.
Steps:
-
API Setup:
- For this exercise, let's use
https://randomuser.me/api/ which provides random user data.
-
FlutterFlow Project:
- Start a new FlutterFlow project.
- Go to the API section and set up a new API integration with the endpoint provided above.
- Define the expected response fields based on the API's documentation.
-
Fetching and Displaying Data:
- Place a
Button widget on the canvas.
- Set the button's
onPressed property to call the API endpoint you set up.
- Create a
FutureBuilder widget or data binding to display the API response on the screen.
- Use
Text widgets to display specific fields like name or email based on the API response.
-
Run Your FlutterFlow App:
- Save your flow and preview the app.
- Click the button, which should fetch the data from the API and display it within the
Text widgets.
Remember, these exercises are simplified for learning purposes. Real-world scenarios will typically involve more complex interactions and error handling. As you become more comfortable with the basics of FlutterFlow, you can incrementally add complexity to your projects such as form validation, managing state with Providers or Riverpod, and handling different types of responses and errors from APIs.