Dart & Flutter- Intro

Rishi Prakash
2 min readNov 16, 2023

--

Dart is an open-source general-purpose programming language; Originally developed by Google.

Dart is an object-oriented language with C-style syntax.

It supports programming concepts like interfaces, classes, unlike other programming languages Dart doesn’t support arrays. Dart collections can be used to replicate data structures such as arrays, generics, and optional typing.

Widgets

In Flutter, Everything is a widget.

Widgets are basically user interface components used to create the user interface of the application.

In Flutter, the application is itself a widget. The application is the top- level widget and its UI is build using one or more children (widgets), which again build using its children widgets. This composability feature helps us to create a user interface of any complexity.

For example, the widget hierarchy of the hello world application-

  • MyApp is the user created widget and it is build using the Flutter native widget, MaterialApp.
  • MaterialApp has a home property to specify the user interface of the home page, which is again a user created widget, MyHomePage.
  • MyHomePage is build using another flutter native widget, Scaffold
  • Scaffold has two properties — body and appBar
  • body is used to specify its main user interface and appBar is used to specify its header user interface
  • Header UI is build using flutter native widget, AppBar and Body UI is build using Center widget.
  • The Center widget has a property, Child, which refers the actual content and it is build using Text widget

Concept of State

Flutter widgets support State maintenance by providing a special widget, StatefulWidget. Widget needs to be derived from StatefulWidget widget to support state maintenance and all other widget should be derived from StatefulWidget. Flutter widgets are reactive in native. This is similar to reactjs and StatefulWidget will be auto re- rendered whenever its internal state is changed. The re-rendering is optimized by finding the difference between old and new widget UI and rendering only the necessary changes

Data Types

Variables

You can declare most variables without explicitly specifying their type using var. Thanks to type inference, these variable’s types are determined by their initial values:

var name = 'Voyager I';
var year = 1977;
var antennaDiameter = 3.7;
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = {
'tags': ['saturn'],
'url': '//path/to/saturn.jpg'
};

Inheritance

Dart has single inheritance.

--

--