Study Notes Flutter
Study Notes Flutter
Variable
If we use ‘var’ it is a dynamic variable. It can hold any type of values.ie we can change the
value that is being hold by this variable at any stage of the program.
Int, string, Bool, const, final,
Concatenation &- before variables
26-03-2020
==, !=>,<,>=,<=,
Is, is!
If
Logical operator
! negating an expression
|| OR
&& AND
While and do while loop
Switch case and default
Functions
Return functions
>= to return an expression-simplifying the code
While printing remember- function is an expression, use ${}
o Void- doesn’t return anything
o String
o Int
Return functions with parameters
String showname(string name)=>” Hello $name”
String sayhello(String name, String lastname, int age)
Optional parameters in functions [int age]
Variables defined inside functions cannot be accessed outside the functions
27-03-2020
Creating the classes- with various instance variables or otherwise called characteristics
Assign the class to a variable – var mic = new Microphone
There are two methods to create the actual object. Either with a constructor or without a
constructor.
Constructor- Microphone(this.name, this.color,this.model)
Two or more constructors in the class definition so that mics with different characteristics
can be instantiated.
2nd Cosntructor- Microphone.initialize(this.name, this.color,this.model)
Getters and Setter -to check again
Inheritance of classes-
Class Person extends Anoop – Anoop inherits the characteristics of Person class
Override of methods inherited from parent class- define the method in the class and print
what you want.
Inheritance with constructor – in the child class press red button to create the constructor
for child class
After creating the class using red button-additional parameters can be added using
(this.elevation) command
Abstract class
Basically is the mould class -like class Animal
Class person implements Animal class;
28-03-2020
Collections
Flutter App
While using the scaffold widget- calling the app in home page is different. Need to call as a
new material app
Void main= >runApp(new MaterialApp(
Home: Scaffoldexample(),
));
Inkwell app
Icon button creation, adding gesture to a button,
Inside coloumn widget, use children for widget creation not child.
30-03-2020
14-04-2020
inside main
Sayname(“Anoop”, “TS”);
- In functions like above any values can be made optional by putting a square bracket –
ex: String Sayname(String name, [String lastname]) => “$name $lastname”;
- If a variable is defined inside a function that variable will not be accessible anywhere outside
that function.
Creating a Constructor
- Keyword ‘extends’ can be used to inherit all the properties of a already existing class.
- To create a constructor for extended class – click on the yellow button. Within this
constructor we can add the instances of that particular class using ‘this.character’
expression.
- For Overriding methods of an inherited class – type the method in the extended class and
override.
Abstract class
var onlystring = new List<String>(); // to create a list that can contain only string
values.
ANGELA
- The items which are written in small letters are the properties of a class for ex ‘appbar:’ of a
Scaffold class. For each class there will be a bunch of properties.
- Hot reload works only if the code is written inside the stateless widget.
- Hot reload only loads the changes that have been made in the code. It doesn’t compile the
whole code from the beginning and that is why it is so fast. Also hot reload doesn’t change
the state of the project.(Count of donuts not changed)
- Hot restart similar to hot restart but will also change the state of the project.(Count of
donuts set to initial state of zero)
- Container expands to the whole available space if it doesn’t have any children.
- Safearea widget can be used to move the container away from notches.
General Widgets
Safe area –
- Safe area widget can be used to move the container away from notches.
- Left,right,top,bottom- true or false
- Minimum.Edgeinsets.all(value) can be put.
- //left: true,
//minimum: EdgeInsets.all(20),
-
Textstyle
- letterspacing,worspacing –
letterSpacing:2,wordSpacing: 5,
- decoration: TextDecoration.underline,
// decorationColor: Colors.deepPurpleAccent,
// decorationStyle: TextDecorationStyle.solid,
// decorationThickness: 5
-Margin
Padding
-Edgeinsets
Coloumn
Mainaxis size
- Min/max
- Can be set to min or max- accordingly the size of coloumn will be limited to children of
coloumn.
-
Vertical Direction – Up or Down -Children can be laid from top to bottom or vice versa.
- For alignment across the 90 degree axis ie horizontal direction in the case of coloumn.
- End /Start/ Strecth
- Stretch – will stretch the children across the horizontal direction.
Sized Box
- For creating spacing between children
Circle Avatar
Card Class
Divider Class
- To create a line.
- SizedBox(
width: 250,
height: 20,
child: Divider(
color: Colors.white,
thickness: 1.5,
),
),
-
Expanded Class
-The size of the child will adjust as per the screen size.
-flex can be used to determine how much space to be occupied compared to other widgets.
Image
With below code animation will be done forth and back. Instead we can just set the values in the set
state- in that case animations will not be done back and forth.
FlatButton(
child: Text("Animate"),
onPressed: (){ setState(() {
height=height==100?200:100;
width =width==100?200:100;
color=color== Colors.tealAccent?Colors.red:Colors.tealAccent;
});
),
OutlineButton(
child: Text("Animate CrossFade"),
onPressed: (){setState(() {
FirstCrossFade =!FirstCrossFade;
});
},
),
Animated Opacity
AnimatedOpacity(
opacity: opacity,
duration: Duration(seconds: 2),
child:Container(
height: 200,
width: 200,
child:Image.asset("images/apple.png"),
)
),
OutlineButton(
child: Text("Animate Opacity"),
onPressed: (){setState(() {
opacity =opacity==0?1:0;
});