‹ Back to Home

Dart Basics Before Flutter: Variables, Null Safety, Classes and Async in Two Hours

Every Flutter tutorial assumes you already know Dart, and that's where most beginners quietly get stuck. Spend two hours here on variables, null safety, classes and async/await, and the next two weeks of Flutter will feel a lot less confusing.

Keerthika 8 min read
Follow on Google
Programming Dart Basics Before Flutter: Variables, Null Safety, Classes and Async in Two Hours 8 min left Follow on Google
Dart Basics Before Flutter: Variables, Null Safety, Classes and Async in Two Hours

TamilTech AI summary

  • Dart fundamentals, not widgets, cause most beginner Flutter confusion
  • final is for runtime values, const is for compile-time values
  • ? marks nullable, ! forces a non-null promise, late delays assignment safely
  • Named constructors like Order.freeSample() power many real Flutter widgets
  • Future and async/await are essential the moment your app talks to an API

AI-assisted summary, checked by the TamilTech editorial team.

0:00
0:00
🔒 Listen is for subscribers. Subscribe

முக்கிய விஷயங்கள்

  • Dart is the language Flutter apps are written in — you can't skip it and jump straight to widgets.
  • Null safety (?, !, late) is the single biggest mindset shift coming from Java or JavaScript.
  • final and const look similar but mean different things — mixing them up causes half the beginner errors.
  • Named constructors and arrow functions are Dart's way of keeping widget code short, which is exactly why Flutter leans on them so heavily.
  • Future and async/await handle anything that takes time — API calls, file reads, UPI payment status checks.

What is Dart, in one line, and why should Flutter beginners care?

Dart is the programming language Google built specifically to power Flutter. Think of Flutter as the furniture and Dart as the carpentry tools — you can't build the furniture without knowing how to hold the saw first. Here's the thing nobody tells beginners clearly: almost every "my Flutter app isn't working" problem on forums is actually a Dart problem wearing a Flutter costume. A missing ?, a confused final, a constructor that doesn't take the right arguments — these are Dart issues, not widget issues.

So before you open your first pubspec.yaml, spend a couple of hours purely in Dart. No widgets, no emulator, just a simple main.dart file you can run with dart run. That's the two hours that save you two weeks.

How do you handle variables, final, and const in Dart?

Dart variables are typed, but it's smart enough to guess the type most of the time using var. You rarely write the type by hand unless you want to be explicit.

void main() {
  var city = "Chennai"; // type inferred as String
  int rupees = 500;
  double discount = 10.5;
  bool isPrime = true;

  final today = DateTime.now(); // assigned once, known only at runtime
  const taxRate = 0.18; // fixed at compile time, never changes

  print("$city order total with tax: ${rupees + (rupees * taxRate)}");
  print("Ordered on: $today");
}

The difference between final and const trips up almost everyone. final means "I'll set this once, and I genuinely don't know the value until the app runs" — like DateTime.now(). const means "this value is fixed even before the app starts" — like a GST rate or a fixed string.

Simple rule: if the value needs a clock, a network call, or user input to exist, use final. If it's a hardcoded number or text you're writing yourself, use const.

What's the deal with null safety — ?, ! and late?

This is the part that feels alien if you're coming from older Java or plain JavaScript. In Dart, a variable cannot be null unless you explicitly allow it.

void main() {
  String name = "Arun"; // can never be null
  String? nickname; // the ? means this CAN be null

  nickname = "Aru";
  print(nickname?.toUpperCase()); // safe: prints only if not null

  late String city; // promise: I'll set this before using it
  city = "Madurai";
  print(city);

  String? phone = getPhoneOrNull();
  print(phone!.length); // ! says "trust me, this is not null" — risky
}

String? getPhoneOrNull() => null;

Here's how to read these three symbols without memorising rules. ? after a type means "this box might be empty, handle it carefully." ! after a value means "I personally guarantee this box is not empty" — and if you're wrong, the app crashes immediately. late means "this box is empty right now, but I promise I'll fill it before anyone opens it."

New Dart developers overuse ! because it makes red squiggly lines disappear fast. Resist that. Every ! you add is a small bet that something won't be null — and in a real app with API calls and user input, that bet fails more often than you'd think.

How do functions and arrow syntax work in Dart?

Dart functions look like C-style functions, but for one-line bodies there's a shortcut called arrow syntax that you'll see constantly inside Flutter widget code.

int addGst(int price, double rate) {
  return (price + (price * rate)).round();
}

// Same thing, arrow syntax — no { }, no return keyword
int addGstShort(int price, double rate) => (price + (price * rate)).round();

void main() {
  print(addGst(1000, 0.18));
  print(addGstShort(1000, 0.18));
}

Arrow functions only work when the function body is a single expression. The moment you need an if, a loop, or multiple statements, go back to curly braces. Flutter's build() methods and small helper functions use arrow syntax everywhere, so getting comfortable with it now saves confusion later.

How do classes and named constructors work in Dart?

Flutter widgets are just Dart classes, so understanding classes properly is non-negotiable.

class Order {
  final String itemName;
  final double price;

  Order(this.itemName, this.price); // default constructor

  // Named constructor — a second, clearly labelled way to build the same class
  Order.freeSample(this.itemName) : price = 0.0;

  String summary() => "$itemName costs ₹${price.toStringAsFixed(2)}";
}

void main() {
  var paid = Order("Dosa", 60);
  var free = Order.freeSample("Sauce Packet");

  print(paid.summary());
  print(free.summary());
}

Named constructors are Dart's answer to "I need two different ways to create the same object." Instead of writing confusing optional parameters, you just name the intent — Order.freeSample() reads like English. Flutter itself uses this pattern constantly: Text.rich(), Container.expand() and dozens of widget variants are all named constructors in disguise.

How does Future and async/await actually work?

Anything that takes time in a real app — hitting an API, checking a UPI payment status, reading a file — doesn't return a value instantly. Dart wraps that "value coming later" idea in a Future.

Future<String> fetchPaymentStatus() async {
  await Future.delayed(Duration(seconds: 2)); // simulates a network call
  return "SUCCESS";
}

void main() async {
  print("Checking payment...");
  String status = await fetchPaymentStatus();
  print("Status: $status");
}

Read it like this: async on a function means "this function will take some time, be patient." Future<String> means "eventually you'll get a String, just not right now." await means "pause here and wait for that Future to finish before moving to the next line." Without await, your code races ahead and tries to print a value that hasn't arrived yet.

Which mistakes get people into trouble?

Forgetting await is the classic one — you get a weird Instance of 'Future<String>' printed instead of the actual value, because you never waited for it.

Overusing ! to silence null-safety warnings is the second big trap — it compiles fine, then crashes at 2am in production when an API genuinely returns null.

Mixing up final and const on values that need runtime data — like trying to make DateTime.now() a const — throws a compile error that confuses total beginners because the message doesn't say "use final instead" in plain words.

Writing arrow functions for multi-statement logic and then wondering why the IDE keeps underlining red — arrow syntax is strictly one expression, nothing more.

Where is this used in Indian companies and interviews?

Most Indian product companies and service firms doing Flutter work — from Bengaluru startups to the Flutter teams inside larger fintech and e-commerce players — test exactly these fundamentals in the first interview round before touching a single widget. Interviewers love asking "what's the difference between final and const" and "explain null safety with an example" because it instantly separates someone who copy-pasted a Flutter tutorial from someone who actually understands Dart. Async/await questions show up the moment the interview touches API integration, which is basically every Flutter job description you'll see for freshers today.

What should you do now?

Open any online Dart playground or install the Dart SDK, skip Flutter entirely for one evening, and rewrite every code block above in your own words — change the variable names, break something on purpose, read the error message fully. As practice, build a small Student class with a named constructor Student.topper() that auto-sets marks to 100, add a nullable String? remarks field, and write one async function that "fetches" the student's result after a two-second delay using Future.delayed. If you can do that without looking anything up, Flutter widgets will feel surprisingly easy next.

Frequently asked questions

5

Do I need to learn Dart separately before starting Flutter?

Yes, even a couple of hours helps a lot. Flutter tutorials assume you already know Dart syntax, variables, and null safety, so skipping this step usually means getting stuck on basic errors instead of learning widgets.

What is the real difference between final and const in Dart?

const is fixed at compile time and must be known before the app even runs, like a tax rate you type in yourself. final is set once but can hold a value only known at runtime, like DateTime.now() or data from an API.

Why does Dart force null safety with ? and !?

Null safety stops a huge class of crashes before they happen. The ? marks a variable that might be empty, forcing you to handle that case, while ! is an explicit promise from the developer that a value is definitely not null.

What does the late keyword actually do in Dart?

late lets you declare a variable without giving it a value immediately, as long as you promise to assign it before it's ever read. It's commonly used for variables set inside initState in Flutter widgets.

Is async/await necessary for a Flutter beginner to know early?

Yes, because almost every real app calls an API, reads a database, or checks a payment status, and all of these use Future and async/await in Dart. Learning it before Flutter makes network code far less confusing.

Get tomorrow’s tech news on WhatsApp

One short update a day, free. Follow the TamilTech channel.

What do you think?

people reacted

Keerthika

TamilTech editorial team · 3,448 articles

Keerthika is an editor at TamilTech, the Tamil and English technology publication founded by Praveen Kumar S. She covers AI, smartphones, gadgets, EVs, startups and cybersecurity i...

More from Keerthika

Ask TamilTech on WhatsApp

Tech doubt? Ask in Tamil or English — our WhatsApp assistant answers from TamilTech articles in seconds.

Related stories

Comments (0)

| Supports **bold**, *italic*, `code`

Be the first to comment!

Next story How to Install Python and Set Up VS Code the Right Way (Windows, Mac, Linux)
Tamiltech

Tamiltech

Install app for faster access

Earn XP 🏆
WhatsApp
Notifications