Since I began learning flutter, dart was a new language for me. I came to know that dart is the most similar to java language which also I was just partially informed in.

And there I was stuck

So here goes a small basics chart I made gpt give me that seems to be quite helpful in catching the basic flow of the code it generates futher for my dart project:


βœ… Essential Dart Concepts for Flutter Beginners

1. Variables & Data Types

int age = 25;
double price = 9.99;
String name = 'Anu';
bool isLoggedIn = true;
var anything = 'Can be any type';
  • var = type inferred automatically
  • final / const = cannot be changed after initialization

    final name = 'Anu';  // run-time constant
    const pi = 3.14;     // compile-time constant
    

2. Functions

String greet(String name) {
  return 'Hello, $name!';
}

void printMessage() {
  print('Hi there!');
}
  • You can also write short functions like:

    int square(int x) => x * x;
    

3. Classes & Objects

class Person {
  String name;
  int age;

  Person(this.name, this.age);

  void introduce() {
    print('I am $name and I am $age years old.');
  }
}
  • Create an object:

    var p = Person('Anu', 21);
    p.introduce();
    

4. Constructors

  • Default, named, and optional constructors:

    class Product {
      String name;
      double price;
    
      Product({required this.name, required this.price});
    }
    
    var p = Product(name: 'Shoes', price: 99.99);
    

5. Collections: Lists, Maps, Sets

Lists (Arrays)

List<String> fruits = ['apple', 'banana'];
fruits.add('mango');

Maps (Key-Value pairs)

Map<String, int> scores = {'math': 90, 'english': 85};
print(scores['math']);

Sets (Unique items)

Set<String> cities = {'Paris', 'London', 'Paris'};
print(cities.length);  // 2

6. Control Flow

  • If/Else, For, While, Switch
if (age > 18) {
  print('Adult');
} else {
  print('Minor');
}

for (var i = 0; i < 3; i++) {
  print(i);
}

7. Null Safety

  • Dart doesn’t allow null unless you tell it:
String? name;  // nullable
name = null;   // OK

String name2 = 'Anu';
// name2 = null; // ❌ Error

8. Async / Await & Futures

Used when dealing with APIs, delays, etc.

Future<String> fetchData() async {
  await Future.delayed(Duration(seconds: 2));
  return 'Data loaded';
}

void main() async {
  print('Start');
  String data = await fetchData();
  print(data);
}

9. Getters & Setters

class Rectangle {
  double width, height;

  Rectangle(this.width, this.height);

  double get area => width * height;

  set resize(double factor) {
    width *= factor;
    height *= factor;
  }
}

10. Basic Error Handling

try {
  int result = 10 ~/ 0;
} catch (e) {
  print('Caught error: $e');
}

🧠 Bonus: Flutter-Specific Must-Knows

Concept Why it matters
main() Entry point of every Dart/Flutter app
Widget Everything is a widget (UI blocks)
StatelessWidget For static UIs
StatefulWidget For interactive UIs
setState() Rebuilds part of the UI
async/await Needed for API, DB, etc. in Flutter

βœ… Summary: Start With These 10

βœ… Must-Learn Concepts
βœ… Variables & Types
βœ… Functions
βœ… Classes & Objects
βœ… Collections
βœ… Null Safety
βœ… Control Flow
βœ… Async/Await
βœ… Constructors
βœ… Getters/Setters
βœ… Error Handling

This site uses Just the Docs, a documentation theme for Jekyll.