Menu
CoddyTech

Numbers

Part of the Your First App section of Coddy's Flutter journey. Lesson 13 of 32.

Dart has two kinds of numbers. An int is a whole number, and a double can have a decimal point:

int people = 4;
double height = 1.75;

You can do math with them: + adds, - subtracts, * multiplies and / divides. Inside a string, put the calculation in ${} and Dart shows the result:

Text('Seats: ${people * 2}')   // Seats: 8

Outside the braces, * is just a character in the text.

challenge icon

Challenge

Easy

The app knows how many apples you buy and their price. Make it show Total: 7.5, worked out from the two variables with *.

Try it yourself

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    int apples = 3;
    double price = 2.5;
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Text('Total: ?', style: TextStyle(fontSize: 32)),
        ),
      ),
    );
  }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Your First App

Practice on your own: Online Flutter compiler