0
0
Fluttermobile~5 mins

Data types (int, double, String, bool) in Flutter

Choose your learning style9 modes available
Introduction

Data types help us tell the app what kind of information we want to store. This makes the app work correctly and avoid mistakes.

When you want to store whole numbers like age or count.
When you need numbers with decimals like price or temperature.
When you want to store words or sentences like names or messages.
When you want to store true or false values like a switch or a yes/no answer.
Syntax
Flutter
int myNumber = 10;
double myDecimal = 3.14;
String myText = 'Hello';
bool isTrue = false;

int is for whole numbers without decimals.

double is for numbers with decimals.

String is for text inside single or double quotes.

bool is for true or false values.

Examples
This stores the age as a whole number.
Flutter
int age = 25;
This stores a price with decimals.
Flutter
double price = 19.99;
This stores a short text message.
Flutter
String greeting = 'Hi there!';
This stores a true/false value to check login status.
Flutter
bool isLoggedIn = true;
Sample App

This Flutter app shows four texts on the screen, each displaying a different data type value.

Flutter
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    int myInt = 42;
    double myDouble = 3.14;
    String myString = 'Flutter is fun!';
    bool myBool = true;

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Data Types Example')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('int: $myInt'),
              Text('double: $myDouble'),
              Text('String: $myString'),
              Text('bool: $myBool'),
            ],
          ),
        ),
      ),
    );
  }
}
OutputSuccess
Important Notes

Use int for whole numbers only, no decimals allowed.

double can store decimals but uses more memory than int.

String values must be inside quotes.

bool only accepts true or false.

Summary

int stores whole numbers.

double stores decimal numbers.

String stores text.

bool stores true or false.