How logic works
Logic is everything your app does besides looking good: reacting to a tap, remembering a value, choosing what to show, loading data from the internet. In Nowa you build it visually, by picking steps from menus instead of typing code, and Nowa writes the code for you.
You don't need any programming background. The ideas on this page are the same ones every app uses, explained in everyday terms.
How the pieces fit
- An event starts it. A tap, a long press or a typed letter fires an event.
- A function holds the steps. You stack the steps in Circuit, and they run from top to bottom.
- Steps use data. They read and change values stored in variables, params and global states.
- Widgets show the result. A property linked to a value shows it, and an expression can turn it into a calculation or a choice.
For example, picture the + button next to a product's quantity in a shop app. Its On Pressed event runs a function that adds one to a quantity variable and refreshes the screen. A text widget linked to quantity shows the new number.
The pieces
| Idea | In plain words | Learn more |
|---|---|---|
| Event | Something that happens, such as a tap, a long press or typing. It starts your logic. | Respond to taps and other events |
| Function | A named list of steps you can run from many places, like a recipe. | Create functions |
| Circuit | The visual editor where you stack the steps of a function. | Build logic in Circuit |
| Variable | A value a screen or component remembers while it's open, such as the number of items in a cart. | Store data in variables |
| Param | A value handed to a screen or component from outside, such as the product a details screen shows. | Pass data with parameters |
| Global state | Values and functions the whole app shares, such as a cart. | Share data across your app |
| Condition (If) | A yes-or-no question that decides which steps run, such as "Is the cart empty?" | Branch with If |
| Error handling (Try) | A backup plan for steps that can fail, such as loading data without an internet connection. | Handle errors with Try |
| Model | A custom type that groups related values, such as a Product with a name and a price. | Data models |
| Expression | A formula that gives a value: a link, a calculation or a condition. | Expressions and conditions |
| Action | A ready-made step, such as showing a message or opening a link. | Show dialogs, sheets, snackbars and pickers, Navigate between screens, Use ready-made actions |
| Route | The path that opens a screen, such as /recipe/:id. The Router panel lists them all. | Set up routes in the Router panel |
Which one do I need?
Most logic questions come down to a few choices:
| You want to... | Use |
|---|---|
| Remember a value on one screen, such as a counter or what someone typed | A variable |
| Hand a value to a screen or component, such as the product to show | A param |
| Share a value between screens, such as a cart or the signed-in user | A global state |
| Run the same steps from several places | A function |
| Do one thing or another, depending on a value | An If |
| Cope with a step that can fail, such as an internet request | A Try |
| Keep a small value after the app closes, such as a chosen language | Shared Preferences |
Not sure? Start with a variable on the screen that needs it, and move it to a global state once a second screen needs it too. Data and state tips goes deeper.
Everything you build turns into real app code that you own. You never have to read it, but code mode shows it whenever you're curious.
Switch to Agent mode and describe what should happen: "When the user taps Add to cart, add the product to the cart and show a message." Design mode builds the look and flow without logic. Then open what it built in Circuit to check or change it. See Design, Plan and Agent modes.
Where to start
- Respond to taps and other events: make a button show a message.
- Store data in variables: make your screen remember and show a value.
- Build logic in Circuit, then make decisions, handle errors and repeat steps with If, Try and loops.
- Navigate between screens: send people to another screen.
Next steps
- Connect data and services: need data from a server, or sign-in?
- Preview and test: try your app at every step.
- Find and fix problems: something not working?
- Build a great app: a complete walkthrough and tips for design, Nowa AI, data and shipping.