Day -1 #30daysofFlutter

What is Flutter?

Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications for Android, iOS, Linux, macOS, Windows, Google Fuchsia, and the web from a single codebase.

Before we begin a very important question that needs to be answered is "Why should someone learn flutter?"
I won't use flattering words to convince you so I let chatGPT answer this-

Sounds intimidating right?
So here is how my first day went

  • Installation and setup

  • Basic intro to Flutter (widgets)

  • Dart basics

    -Variables
    -Lists

Instead of taking courses and devoting days to completing them, I opted to take a different approach and dive straight into building.

Installation and setup-

To get started with Flutter you need to install the Flutter SDK https://docs.flutter.dev/get-started/install

Once you have selected your operating system you can follow the docs to get Flutter up and running on your system.

Installation of IDE (Android Studio)

A text editor is an important tool when you decide to code and Android Studio does the job for me, you can always use other editors like VS Code if you are accustomed to them.

For the installation of Android Studio
Download and run the exe file from here- https://developer.android.com/studio

Flutter Basics (widgets)

In Flutter, widgets are like building blocks that developers use to create the different parts of a mobile app. They are like pieces of a puzzle that fit together to make the app look and work the way it should.

Each widget has a special job to do. For example, a button widget is used to create a button that a user can tap on to perform an action, like submitting a form or navigating to a different screen. Another example is a text widget, which is used to display text on the screen in different fonts, colours, and sizes.

Widgets can also be combined to create more complex user interfaces, like a login screen or a dashboard with different sections and buttons.

Flutter widgets follow the tree structure as shown, widgets can be nested inside each other to form meaningful trees. Each of these widgets has its individual properties which can be used to customise the appearance and functionality of the interface.

Dart basics

Flutter uses its language "Dart" for building cross-platform apps. If you have prior knowledge of any object-oriented programming language like JS or C++ then Dart is a cakewalk for you. If you are new to programming I suggest you learn a language first if your goal is Flutter then you may choose Dart.

Variables-

Variables are like containers which are used to store values in Dart, these can be numbers, strings, or any other data type. Dart is a statically typed language, which means that you need to declare the data type of a variable before you can use it.

Here is how you declare variables in Dart-

void main() {
//variableType NameOfthevariable = value ;
  int number=9;
  String s = 'name';
  bool val = true; //A boolean data type stores only 2 values either true or false
}

Variables in Dart are static which means the type of the variable can't be changed post-declaration, but if you want to declare a dynamic variable (which can store any data type) the 'dynamic' keyword is to be used before the name of the variable.

void main() {
  int number=9;
  number='name';//This will give an error bc number is of type int 
}

To dynamically declare variables-

void main() {
  dynamic number=9;
  number= 'string';//this is completely fine as the varible is dynamic which allows data of any type to be stored.
}

Lists-

A list is a collection of data that share similarities with arrays in languages like JS and C++, as well as with Python's lists. To create a list, one needs to use the 'List' keyword and square brackets.

void main() {
  List ages= [10,20,'Dart'];//should be avoided completely
}

While it is possible in theory to store multiple data types within a single list, this approach is generally not recommended and should be avoided. It is a better practice to declare the data type of the list using angle brackets '<>' to ensure consistency.

void main() {
  List<int> ages= [10,20,25];//Now when you try to  
}

List methods

  1. add(): Adds an element to the end of the list.

     myList = [1, 2, 3];
     myList.add(4); // [1, 2, 3, 4]
    
  2. insert(): Inserts an element at a specific index in the list.

myList = [1, 2, 3];
myList.insert(1, 5); // [1, 5, 2, 3]
  1. remove(): Removes the first occurrence of an element from the list.
myList = [1, 2, 3, 2];
myList.remove(2); // [1, 3, 2]
  1. clear(): Removes all elements from the list.
myList = [1, 2, 3];
myList.clear(); // []
  1. length: Returns the number of elements in the list.
 myList = [1, 2, 3];
myList.length; // 3
  1. indexOf(): Returns the index of the first occurrence of an element in the list.
 myList = [1, 2, 3, 2];
myList.indexOf(2); // 1
  1. sort(): Sorts the elements in the list.
myList = [3, 1, 2];
myList.sort(); // [1, 2, 3]

I hope you enjoyed reading my blog as much as I enjoyed writing it. Thank you for your time and attention.