Chapter 2. A brief intro to Dart

 

This chapter covers

  • Dart’s Hello, World!
  • Anatomy of a Dart program
  • Basic Dart syntax such as control flow, loops, and functions
  • Object-oriented programming in Dart
  • Using I/O Dart libraries

This book is about building mobile apps with Flutter. But you can’t write a Flutter app without learning a bit about the Dart programming language first. The good news is that Dart is also quite easy to pick up. If you’re already comfortable enough with Dart that you understand the following code block, you can skip this chapter:

class CompanyContext extends StateObject {
  final bool isLoading;
  String _companyId;

  CompanyContext({
    this.isLoading = false,
  });
  String get companyId => _companyId;
  void set companyId(String id) {
    _companyId = id;
    _initApp();
  }

  factory CompanyContext.loading() => CompanyContext(isLoading: true);

  @override
  String toString() => 'CompanyContext{isLoading: $isLoading, _companyId: 
 $_companyId}';
}

2.1. Hello, Dart!

2.1.1. Anatomy of a Dart program

2.1.2. Adding more greetings

2.1.3. I/O and Dart libraries

2.2. Common programming concepts in Dart

2.2.1. Intro to Dart’s type system

2.2.2. Comments

2.2.3. Variables and assignment

2.2.4. Operators

2.2.5. Null-aware operators

2.3. Control flow

2.3.1. if and else

2.3.2. switch and case

2.3.3. Advanced switch usage

2.3.4. Loops

2.4. Functions

2.4.1. Anatomy of a Dart function

2.4.2. Parameters

2.4.3. Default parameter values

2.4.4. Advanced function concepts

2.4.5. Lexical scope

2.5. Object-oriented programming (in Dart)

2.5.1. Classes

A note about the (lack) of the new keyword

2.5.2. Constructors

2.5.3. Inheritance

2.5.4. Factories and named constructors

2.5.5. Enumerators

sitemap