More
Gallery

Flutter & Dart Basics

Abhay Bairagi
Jan. 4, 2024



Understanding Flutter: Building Native Cross-Platform Apps

Flutter is a powerful toolkit that simplifies the development of high-quality mobile applications. It provides a seamless way to create natively compiled applications for mobile, web, and desktop from a single codebase.

Native Apps:

Native apps are developed for specific platforms like iOS or Android. They are built using platform-specific programming languages (Swift or Objective-C for iOS, Java or Kotlin for Android) and can access device-specific features.

Cross-Platform:

Creating cross-platform apps means a single codebase can be used to develop applications that run on multiple platforms, reducing development time and efforts. Flutter achieves this by compiling Dart code to native machine code, allowing it to run efficiently on various platforms.

Flutter Components:

  1. SDK (Software Development Kit): Flutter provides a comprehensive SDK equipped with tools, libraries, and APIs necessary for app development.
  2. Framework/Widget Library: Its framework offers a rich set of pre-designed and customizable widgets, enabling the creation of visually appealing and responsive user interfaces.

Advantages of Flutter:

  • Single Codebase: Developers can write code once and deploy it across multiple platforms, reducing development time and effort.
  • Hot Reload: Flutter's hot reload feature allows real-time code changes to be reflected instantly in the app, making the development process faster.
  • Performance: Flutter apps perform at near-native speeds due to the compilation of Dart code to native machine code.
  • Rich Widgets: The extensive library of widgets enables the creation of highly customized and visually engaging interfaces.

Understanding Dart:

Dart is the programming language used to write Flutter apps, developed by Google specifically for building high-performance applications.

Strongly Typed:

In Dart, being strongly typed means that variables are bound to specific data types and require explicit declaration or inference during variable creation, enhancing code reliability and readability.

Data Types in Dart:

Dart supports various data types, including integers (int), floating-point numbers (double), strings (String), boolean values (bool), lists, maps, and more.

Variables & Functions in Dart:

  • Variables: Dart allows variable declaration using var for type inference or explicitly defining the data type using keywords like int, double, etc.

    • Example: var age = 20; or int age = 20;
  • Functions: Dart functions can be declared with specified parameter types and return types.

    • Example:
      num addNumbers(num n1, num n2) { return n1 + n2; }

Object-Oriented Concepts in Dart:

  • Class and Object: Dart is object-oriented, supporting classes and objects. Classes act as blueprints for creating objects, encapsulating data and behavior.
    • Example:
      class Person {
          String name;
          int age;
          Person(this.name, this.age); // Constructor
          void greet() {
              print('Hello, my name is $name and I am $age years old.');
         }
      }
      void main() {
      var person = Person('Alice', 25);
      person.greet();
       
      // Output: Hello, my name is Alice and I am 25 years old.
      }

Flutter and Dart together provide a robust platform for building modern, efficient, and visually appealing cross-platform applications with ease.