Sub topic 1
What Flutter and Dart are
Prerequisites
This chapter assumes that you understand variables, functions, and classes. You should also be comfortable using a terminal. Experience with Java, Kotlin, Swift, C#, or another object-oriented language is useful, but you do not need to know Dart.
Dart: the language
Dart is a general-purpose programming language developed by Google. Flutter uses Dart for application logic, user-interface code, tests, and configuration.
Dart is object-oriented. Most values are objects, and classes define reusable types. It also supports:
- Static type checking, which catches many mistakes before the program runs.
asyncandawaitfor asynchronous work such as network requests.- Null safety, which makes the type system distinguish between values that can be
nulland values that cannot. - Ahead-of-time compilation for production builds.
- Just-in-time compilation during development, which helps Flutter update an application quickly.
A Dart program starts at a main function. The following program can run with the Dart SDK:
void main() {
const language = 'Dart';
print('This app uses $language.');
}The const keyword declares a value that does not change. $language inserts the variable's value into the string.
Flutter: a UI toolkit
Flutter is an open-source UI toolkit for building applications from one codebase. It supports mobile, web, desktop, and embedded targets. A toolkit is a collection of libraries and tools that helps you build a particular type of software.
Flutter applications describe their interface with widgets. A widget is an object that represents part of the interface or its behavior. Text, buttons, padding, rows, screens, and even the application itself are widgets.
Flutter includes its own rendering engine. Instead of translating every widget into a platform-specific UI control, Flutter paints its interface to the target platform. This gives the same Dart and widget code a consistent visual model across platforms.
Flutter still connects to platform features such as cameras, notifications, and file systems. Dart code can use Flutter plugins or platform channels to communicate with Android, iOS, Windows, macOS, Linux, and browser APIs.
How Dart and Flutter work together
Dart supplies the programming language and runtime behavior. Flutter supplies the framework APIs, widgets, rendering system, project tools, and platform integrations.
A small Flutter application might look like this:
import 'package:flutter/material.dart';
void main() {
runApp(const GreetingApp());
}
class GreetingApp extends StatelessWidget {
const GreetingApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello, Flutter'),
),
),
);
}
}runApp makes the supplied widget the root of the application. MaterialApp provides common Material Design behavior. Scaffold supplies a basic screen structure, and Center positions its child. The build method describes the widget subtree that Flutter should display.
Flutter follows a declarative UI model. You describe what the interface should look like for the current application state. When that state changes, Flutter calls build again where necessary and updates the rendered result.
When Flutter is a good fit
Flutter is useful when you want one shared codebase and a consistent interface across several platforms. It is especially effective for applications with custom visual designs and frequent UI iteration.
Native platform development can be a better choice when an application depends heavily on platform-specific behavior, very small binaries, or the newest platform APIs immediately after release. The choice depends on your target platforms, team skills, performance needs, and how much code you can share.
Exercise
Which part of the Flutter stack is responsible for variables, classes, and asynchronous functions: Dart or Flutter?
Show answer
Dart. Flutter uses Dart but provides the framework, widgets, rendering system, and platform integrations.