Using APIs
Once you have defined your APIs, you can connect them to your UI. In Digia, there are three primary ways to use an API depending on your needs.
1. FutureBuilder (Load on Render)
The FutureBuilder widget is used to fetch data as soon as a widget is rendered on the screen.
Best For
Page Load: Fetching data when the user lands on a screen (e.g., getting User Profile on the Profile Page).
Widget Load: Loading async data for a specific section (e.g., a "Trending Now" section on the Home Page).
How to use
Drag a
FutureBuilderwidget onto your canvas.In the properties panel, select the API Call you want to run.
Bind Arguments: If your API needs parameters (like
userId), bind them to variables (e.g.,PageParams).Handle States: To manage different API states (Loading, Success, Failure), you can use a ConditionalBuilder widget.
Loading: Show a Spinner or Skeleton loader.
Success: Show the actual content (access data via
apiResponse).Error: Show an Error message or Retry button.
2. Paginated List View (Infinite Scroll)
For lists that contain too much data to fetch at once (like a Social Feed or Product Catalog), use the PaginatedListView.
Best For
Long lists where you need "Load More" functionality as the user scrolls.
How to use
The widget handles the complexity of "page numbers" and "offsets" for you.
Select the
PaginatedListViewwidget.Bind it to an API that supports pagination (accepts
pageoroffset/limitparams).Digia automatically calls the API for the next page when the user scrolls to the bottom.
3. Call REST API Action (Event Driven)
Use the Call Rest API Action when you need complete control over when the API is called.
Best For
Button Clicks: "Submit Form", "Login", "Add to Cart".
Fire & Forget: Sending analytics or logs where you don't need to show the result immediately.
Chain Reactions: Calling an API after a form validation succeeds.
How to use
Select an interactive widget (like a Button).
Add an Action: Call Rest API.
Select which API to call.
Handle Response:
On Success: Store the result in a Variable (App/Page State) or Navigate to another page.
On Failure: Show a Toast or error dialog.
Last updated