Variables

Variables in Digia allow you to store and manage data throughout your app. They come in two main categories: Basic Data Types for storing standard values, and Controller Types for controlling widget behavior and runtime interactions.


📦 Basic Data Types

Basic data types store standard values like text, numbers, and structured data.

Type
Description
Documentation

String

A sequence of characters for text values

Number

Integers and decimal numbers

Boolean

true or false values

JSON

Dynamic map-like structure with key-value pairs

List

An ordered array of values

StringNumberBooleanJSONList

🧰 Controller Types

Controller types are special variables with methods that control widget behavior at runtime. Use the Control Object action to invoke their methods.

Type
Description
Supported Widgets
Documentation

Scroll Controller

Controls scrolling behavior

ListView, GridView, Smart Scroll View, Animation Builder

Page Controller

Manages page navigation in PageView

PageView, Animation Builder

Text Field Controller

Manages text input fields

Text Form Field

Stream Controller

Pushes and listens to data streams

Stream Builder

Async Controller

Manages async state and cache invalidation

Future Builder

Timer Controller

Controls timer operations

Timer

Scroll ControllerPage ControllerText Field ControllerStream ControllerAsync ControllerTimer Controller

� Variable Scope

Variables can be defined in different scopes depending on where you need to use them:

Page State

Variables defined in Page State are:

  • Mutable (can be changed)

  • Scoped to the current page

  • Reset when navigating away from the page

  • Ideal for temporary UI state, form data, or page-specific logic

Page Properties

Variables defined in Page Properties are:

  • Immutable (read-only)

  • Passed as arguments when navigating to the page

  • Used to pass data between pages

  • Ideal for IDs, configuration, or data from previous pages

App State

Variables defined in App State are:

  • Mutable (can be changed)

  • Global across the entire app

  • Persist across page navigation

  • Ideal for user data, authentication state, or app-wide settings


🎯 Best Practices

  • Use appropriate types: Choose the simplest type that fits your data (String for text, Boolean for toggles, etc.)

  • Name descriptively: Use clear, descriptive names (userName instead of u1)

  • Initialize with defaults: Always set initial values to avoid null/undefined errors

  • Scope appropriately: Use Page State for temporary data, App State for persistent data

  • One controller per widget: Each controllable widget should have its own controller variable

  • Clean up controllers: Close streams and clean up controllers when no longer needed


Last updated