Data Types

In Digia, Variables are containers for data. Every variable has a specific Type, which determines what kind of data it can hold and what operations you can perform on it.

We categorize types into two main groups: Scalar Types (Primitive values) and Controller Types (Objects that control UI).

Scalar Types

These are the fundamental building blocks of your data.

[!TIP] Data Manipulation: Data is rarely static. You often need to capitalize a name, calculate a total price, or filter a list. Digia provides built-in Operations for each type to handle this. Check the "Operations" column below to see what's possible.

Type
Description
Examples & Use Cases
Operations

String

Textual data. Can contain letters, numbers, symbols, and emojis.

Ex: "Hello", "user_123" Uses: Usernames, Titles, URLs.

Number

Numeric values (integers or decimals).

Ex: 42, 3.14, -10 Uses: Prices, Quantity, Ratings.

Boolean

True/False values. Logic gates.

Ex: true, false Uses: Toggles, Visibility, Conditions.

JSON

Structured key-value pairs. Standard for API responses.

Ex: {"id": 1, "name": "Digia"} Uses: API Data, Config.

List

Ordered collection of items.

Ex: ["Apple", "Banana"] Uses: Feeds, Galleries, Menus.


Controllers

Controllers are special objects that bind to a Widget to control its behavior programmatically.

[!NOTE] Are Controllers Mandatory? No. Most widgets work perfectly fine without a controller. You only need to create one if:

  • You need to manipulate the widget from outside (e.g., a "Reset" button that clears a TextField).

  • You need the widget's state to persist (e.g., keeping the scroll position when navigating between tabs).

Below is the list of available methods for each controller.

ScrollController

Manages the scroll position of a scrollable widget. Attached to: ScrollView, ListView, GridView.

Method
Arguments
Description

jumpTo

offset (Number)

Instantly jumps to the specified scroll position.

animateTo

offset (Number) durationInMs (Number) curve (String)

Smoothly scrolls to the position over time.

PageController

Controls which page is currently visible in a PageView or Carousel. Attached to: PageView, Carousel.

Method
Arguments
Description

nextPage

durationInMs (Number) curve (String)

Animates to the next page.

previousPage

durationInMs (Number) curve (String)

Animates to the previous page.

jumpToPage

page (Number)

Instantly jumps to the specified page index.

animateToPage

page (Number) durationInMs (Number) curve (String)

Smoothly animates to the specified page index.

TextEditingController

Manages the text content and selection of a text input field. Attached to: TextField, TextFormField.

Method
Arguments
Description

setValue

text (String)

Sets the text content of the field.

clear

-

Clears the text field.

StreamController

Manages a stream of data events. Useful for broadcasting updates to a StreamBuilder. Attached to: StreamBuilder.

Method
Arguments
Description

add

value (Any)

Pushes a new value to the stream, triggering a UI rebuild.

close

-

Closes the stream.

TimerController

Controls a countdown or stopwatch timer. Attached to: Timer widget.

Method
Arguments
Description

start

-

Starts the timer.

pause

-

Pauses the timer.

resume

-

Resumes the timer from where it left off.

reset

-

Resets the timer to its initial state.

AsyncController

Manages the state of an asynchronous operation (Future). Attached to: AsyncBuilder (FutureBuilder).

Method
Arguments
Description

invalidate

-

Forces the Future to re-run (refresh the data).

StoryController

Controls the playback and navigation of a Story widget. Attached to: Story widget.

Method
Arguments
Description

play

-

Plays the story.

pause

-

Pauses the story.

next

-

Skips to the next story item.

previous

-

Goes back to the previous story item.

jumpTo

index (Number)

Jumps to a specific story index.

mute

-

Mutes the story audio.

unMute

-

Unmutes the story audio.

How to use a Controller?

  1. Define it: specific the controller type in your Page State or App State.

  2. Attach it: Select the widget (e.g., ListView) and bind its controller property to your variable.

  3. Call it: In an Action (like "On Tap"), choose Control Object and select your controller variable to trigger a method (like animateTo).

Last updated