0% found this document useful (0 votes)
8 views

Flutter

Uploaded by

vickyrocker
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Flutter

Uploaded by

vickyrocker
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

13.

Module Introduction ->


14. Analyzing A New Flutter Project
Explains the flutter folder structure
15. Form Dart to Machine Code
Dart Code is parsed from top to bottom compiled by Dart and Flutter tools and
converted to Android or iOS machine code is produced which will run on the devices
16. How Programming Languages Work
Generic explanation of how programming language works
17. Starting from scratch : Understanding functions
Functions are a sequence of instructions designed to perform a specific task
when called.
We write function definition in some where else and call that code from
another location
18. Importing Features from Packages
To import features from another packages we need to import first.
First add the package in pubspec.yaml file that you need to use in your
application.
Then import that package and file name in the top of the file where you need
to use that package feature in your application
Like this runApp function is defined in material.dart file so we will first
import that using the following line
import 'package:flutter/material.dart';
19. How flutter app starts
To be precise, a main function in a main.dart file, and it will be executed
automatically by Dart when your app becomes active on a device.
runApp function should be called inside of the main function. Because runApp
tells Flutter what to display on the screen, so which UI elements should be
displayed on the screen.
main() is executed automatically by Dart, runApp() then "tells" Flutter
which widget to draw onto the screen.
20. Understanding Widgets
We need to pass the to-be displayed widget tree as a argument to runApp()
function
A widget tree is a combination of (nested) Flutter widgets that build the
overall interface.
Flutter UIs are created by combining and nesting Widgets
22. Position & Named Arguments
Positional: The position of an argument determines which parameter receives
the value
void add(a, b){
print(a+b);
}
Named: The name of an argument determines which parameter receives the value
void add({a, b}){ // a & b are named parameters (because of the curly
braces)
print(a+b);
}
add(b: 5, a: 10); // 5 is used as a value for b, because it's assigned
to that name; 10 is used as a value for a
By default, positional parameters are required and must not be omitted - on
the other hand, named arguments are optional and can be omitted.
Positional arguments can be made optional by wrapping them with square
brackets ([]):
void add(a, [b]){
print(a+b);
}
Once a parameter is optional, you can also assign a default value to it -
this value would be used if no value is provided for the argument:
void add(a, [b=5]){
print(a+b);
}
Default values can also be assigned to named parameters - which are optional
by default:
void add({a, b=5}){
print(a+b);
}
You can also make named parameters required by using the built-in required
keyword:
void add({required a, required b}) { // a & b are no longer optional
print(a + b);
}
24. Combining Multiple Widgets
One widget can be passed as a argument to another widget.
25. Understanding "const" values
The “const” keyword is used to declare variables that are compile-time
constants.
Compile time constant means its value must be declared while the program is
being compiled.
“const” variables must be assigned a value at the time of their declaration,
and their value must be a compile-time constant.
If a variable is defined with const keyword then we cannot reassign or
redefine that variable.
Performance Optimization:
“const” variables are evaluated and resolved at compile-time, resulting
in improved performance during runtime.
Memory Efficiency:
Since “const” variables are resolved at compile-time, they are stored
in a single memory location, reducing memory usage.
Code Optimization:
Using “const” helps identify and eliminate redundant computations or
objects, improving code efficiency.
27. Understanding Value Types
Dart is a type safe language
In Dart all values are certain type. More than one type is possible and
common
Ex:
'Hello World' -> String, Object
29 -> Int, num, Object
MaterialApp -> MaterialApp, Widget, Object
Type in dart make sure that you're never accidentally using the wrong type in
the wrong place.
Ex:
void main(){
add(5,2);
}

add(int a, int b){


print(a+b);
}
In the above example we can not pass any other type except int as parameter
when call the add function.
28. Configuring Widgets & Understanding Objects
In Dart everything is an object.
A widget is also an object.
34. Understanding Classes
When your application runs on a device and your code executes from top to
bottom then the actual objects are created and stored in memory.
So all these built in widgets are classes which you then turn into objects by
executing them like functions. This process is also called class instantiation.
35. Building Custom Widgets
To build custom widget you need extend that class using stateful or stateless
widget
To pass constructor parameters to the superclass(old way)
Ex:
class Person {
Person(this.name);
final String name;
}

// Old way: before Dart 2.17


class Employee extends Person {
Employee(String name, this.salary) : super(name);
final int salary;
}
Super Initializers
Starting from Dart 2.17, you can pass constructor parameters to the
superclass with a new shorthand syntax.
Ex:
class Employee extends Person {
Employee(super.name, this.salary);
final int salary;
}
39. Introducing Variables
Variables are "Data Containers"
40. Variables and Types
Dart is strongly typed language
Try to use type of the variable at the time of assiging value.
Ex:
String name = "Vignesh";
If you add ? symbol next to the type then the variable can be String value or
null value.
Ex:
String? name;
The above variable "name" value will be null or String.
41. final and const special kindsof "variables"
"final" keyword is a runtime constant and "const" keyword is a compile time
constant.
final is a built in keyword which simply means that this variable never
receive a new value. Once assigned thats it the value will not be changed.
const is a compile time constant. That means the value of the variable is
defined at the time of compile that code.
The main difference between final and const is const variable value is fixed
at the time of compiling the code itself while final variable value can be fixed at
code is executed.
Ex:
const age = 33;
You can not use const keyword to the following
Ex:
const time = DateTime. now();
Because the DateTime. now() value will be known only at the time of executing
the code. Insted of const we can use final
Ex:
final time = DateTime.now();
42. Instance Variables and Configurable Widgets:
You can pass data as a parameter from one widget to another widget.
We can not use the constructor parameter value received inside build method.
For that we need to assign it to that class property.
48. Introducing Stateful widgets
StatefulWidgets, allow us to manage state inside of them.
And state simply is data that may change over time and that should impact the
rendered UI. So if the data changes, the user interface should change.
The state manged here is for the class so the value passed between those
angle brackets should be the class name.
When using "statefulWidget" you will always work with two classes.
1. A subclass of StatefulWidget that defines the widget.
2. A subclass of State that contains the state for that widget and
defines the widget’s build() method.
Note:
Members or classes that start with an underscore (_) are private.
"createState" does not take a value as parameter but it actually returns a
State object.
State, is a generic value type. Hence we have to add angle brackets to
basically inform Dart, which kind of state will be managed here.
createState maintains state for the subclass of the stateful widget that
defines the widget. we need to pass the class name in between the angle brackets.
Ex:
State<ClassName> createState(){
return "state for the Class Name";
}
Create next class which extends the state object returned by createState
function
build method is called inside that state class.

You might also like