Simple Dart program
impot ' dart ' : io ;
void main ()
{
print("hello world"); ==> use for output
stdout.write () ==> is also use for showing output
stdin.readLinesync() ==> use for user input value
}
Create a class and class object
class kamlesh ();
{
new kamlesh ();
kamlesh();
}
small value integer value print and initialization
int a ;
// assingned
a = 5 ;
print(a);
Big value integer value print
bigint longvalue;
longvalue = bigint.parse('Enter long value integer');
print(longvalue);
floating number print and inline
double percentage = 99.65 ;
print(percentage);
// string value print same type so not explaintional about string
boolen value print
bool islogin = false;
//change declaration
islogin = true;
print(islogin);
Var And Dynamic Data Stored
var name = "kamlesh";
// assign new value then
name = 77 ; //error found
// because I am already assign value you must not change a data type
other way to print
// when I am not assign value then not error found and used to different-different data type
and data over-write
var name ;
name = "kamlesh";
name = 77;
name = 9.25;
name = false;
print(name);
// output = false
Dynamic
// when I am use dynamic data stored then I am assigned value different-
different type and no error found and data type over - write
dynamic name = "kamlesh";
dynamic name = "77";
dynamic name = "85.20";
dynamic name = "true";
print(name) // output = true
Function in flutter
***** how to declaration , define and function calling in flutter*****
void main()
{
var myc = myclass();
myc.printName(); //Function calling
}
class myclass(){ //declaration
void printName(){ // Defination
print("hello word");
}
}
*****different-different time different line print in flutter*****
void main ()
{
var myc = myclass();
print("hello ");
print("sir ");
print(7+3 );
print("7+3 ");
print("first maths ");
print("secoud string");
}
class myclass(){
void printName(string name){
print(name);
}
}
****same value print using function in flutter*****
void main()
{
var myc = myclass();
print(myc.add());
}
class myclass(){
int add(){
int a = 5;
int b = 6;
int sum = a + b;
return sum; //when I am select data type then data type must in return then program } exucute
}
*****different value print using function in flutter*****
void main()
{
var myc = myclass();
print(myc.add(9,5));
print(myc.add(300,500));
print(myc.add(10,20));
}
class myclass(){
int add( int num1 , int num2){
int sum = num1 + num2;
return sum;
}
}
*****special function class constructor call using function in flutter*****
void main()
{
var myc = myclass();
print(myc.add(9,5));
print(myc.add(300,500));
print(myc.add(10,20));
myclass(){
print("This is a class constructor call");
}
//when I am created class object then first call class constructor and code exucute then
// second code will be exucuted
}
class myclass(){
int add( int num1 , int num2){
int sum = num1 + num2;
return sum;
}
}
List or Array in Flutter
var ListName = [10,20,30,40];
ListName.add(50); //add a value in ListName list
//empty list create
var name = [];
//use addall
var ListName = [10,20,30,40];
ListName.add(50);
var name.addall(ListName); //complete list in new list transfer
print("$ name /ListName ");
//different-different data type add
var ListName = [10,20,30,40];
ListName.add("kamlesh");
//use insert
var ListName = [10,20,30,40];
lListName.insert(index , element); //like that (3,50)
//insert all
var name = [10,20,30,40];
var ListName = [50,60,70,80];
name.insertall(index,list name); //like that (3,ListName)
//update
var ListName = [10,20,30,40];
ListName[index]="adding part"; //like that ListName[2] = "kamlesh"
//Replace
var ListName= [10,20,30,40];
ListName.replace(start , end , list_name[what's update]);
//like that (0 , 3) = //what is update in list
//Remove
var ListName = [10,20,30,40];
ListName.remove(element); //like that (40) remove in a list
//remove element using index number
var ListName = [10,20,30,40];
ListName.remove(index); //like that (1) index number element removed
//remove range
var ListName = [10,20,30,40];
ListName.removerange(start,end); //like that (start point remove data,ending point)
//operation
print("ListName $ list name . lenght ");
//other using youself at print time
---------->Reverses , First , Last , IsEmpty ,IsNotEmpty Element(index)<----------
Maps and Hashmaps
void main()
{
var map_name={
'key1' : 'value',
'key2' : 90,
'key3' : 90.32,
'key4' : false
};
map_name['kay5'] = 'raman'; // add new keys and value
map_name['key1'] = 'kamlesh'; // value over write
//constructor call
//var mapn = map();
var name ={
name = 'key1' : 'value';
name = 'key2' : 100;
name = 'key3' : true;
};
//operators
void main()
{
var map_name={
'key1' : 'value',
'key2' : 90,
'key3' : 90.32,
'key4' : false
};
print(map_name.isEmpty);
//isEmpty = check map is empty in true and false
//inNotEmpty = check map is not empty in true and false
//lenght = check map lenght
//values = check map values
//containskey('key1')
//containsvalue('false')
//remove('key4')
Final And Constant
final
void main()
final string name;
name = "kamlesh";
name = "nitesh"; // Value could not change
Questions. Try without data type and gives different-different time value assign
constant
1.const name = "kamlesh";
name = "nitesh"; //value could not change
2.const name ;
name = "kamlesh";
name = "nitesh"; //value could not reassign
difference between Final and Constant
Final
//an array create final data type can not change a value but array can change a value
final name = [
"raman",
"nitish",
"nitesh",
"kamlesh",
];
// then
name = ["ishwer","yash","rahul","sahil"]; //value could not change but
name.add("ishwer"); //arrays operators and functions used
Constant
//when i am try to const use with array then array could not be changed
const name = [
"raman",
"nitish",
"nitesh",
"kamlesh",
];
// then
name = ["ishwer","yash","rahul","sahil"]; //value could not change
name.add("ishwer"); //value could not change
If - Else Conditions
//simple use of if
if(){
#value
}
//simple use if and else
if(){
#value
} else {
#value
}
//if else with else if
if(){
#value
}
else if(){
#value
}
else if(){
#value mutiple else if in condition
}
//Nested if else
if(){
#value
}
if(){
#value // in line you should use else if mutiple time
} else {
#value
}
else {
#value
}
Loop
** Types of loop
1.For loop
2.While loop
1.For loop:- for loop simply use print count value
//syntax
for(){
#value
}
for loop use three type value
1.Initial Value gggg
2.Condition
3.Increment And Decrement
examle of for loop
for(i=0;i<10;i++){
print("hello world");
}
2.While loop :- while loop simply use in condition
while loop two type
1.do-while
//example
int no = 100;
do{ //when a condition false then even then code one time exucute ,print
print("no is $no");
} while(no<50);
2.while-do
//example
int no 100;
while(no<50);
{
print("no is $no"); //when a condition false then code exucute but value not print
}
// in run time you should use increament and decreament operators
---------------------------------------------------*******------------------------------------------------
---------------------------------------------------*******------------------------------------------------
Flutter Widget
Container Widget
//basic of container widget so simply you use in body in application
//remove debug tag in application in title section and create title section
title: Text('Flutter Container'),
// debugShowCheckedModeBanner:false,// simply create a container
body: Center(
child: Container(
width: 100,
height: 100,
color: Colors.greenAccent,
child: Text("hello World"),
)Code Exuctue In Emulator
Text Widget
//use text widget with text center
body:Center(child: Text("hello World", style: TextStyle(
fontSize: 50,
color: Colors.black,
fontWeight: FontWeight.w300,
backgroundColor: Colors.greenAccent,
), ))// title name in imgage
Center Widget
//In this paragraph use a container and create their child text with center widgets
body: Center(
child: Container(
width: 300,
height: 150,
color: Colors.black,
child: Center(
child: Text("Hello World",style: TextStyle(
color: Colors.white,
fontSize: 30,
),),
),
),
),
Button Widget
- Buttons are graphical control element that provide
- A user to trigger an event such as talking actions , making choices , searching things , and and many more. They can be placed anywhere in our UI like dialogs , forms, cards, toolbars ,etc
Type of Button
- Text Button (Flat Button)
- Elevated Button (Raised Button)
- Outlined Button
body : TextButton(
child: Text("Click Button"),
onPressed: (){
print("single tapped");
},
onLongPress: (){
print("long tapped");
},
)
body : ElevatedButton(
child: Text("click Button"),
onPressed: (){
print("one tapped");
},
onLongPress: ()
{
print("long preesed");
},
),
3. Outlined Button
body : OutlinedButton(
child: Text("click Button"),
onPressed: (){
print("one tapped");
},
onLongPress: ()
{
print("long preesed");
},
),
Images In Flutter
//First you create a new folder and others folder also in new folder as your wish
//then you copy your images and paste your new folder
//then you pubspec.yaml folder update
assets:
- assets/image///comment out your folder and images URL ,
//then main.dart file link images and show on your applications
Body : Center(
child: Container(
width: 100,
height: 100,
child: Image.asset("assets/image/logo.png"),
),
),
Rows And Columns In Flutter
Rows
//IMP = many time you used to Columns and rows
Main Axis Alignment
body:Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children:[
Text("R1",style: TextStyle(fontSize: 30),),
Text("R2",style: TextStyle(fontSize: 30),),
Text("R3",style: TextStyle(fontSize: 30),),
Text("R4",style: TextStyle(fontSize: 30),),
ElevatedButton(onPressed :(){
},child:Text("Button"))
]
),
)//sapceAround :-start and end half - half space
//spaceBetween :-no starting and ending point sapce
//center:-center in a containers
//start :- start point and by default starting points select
//end :- ending point in your containers
//stretch :- stretch your widget do it your self
Cross Axis Alignment
//same properties used
body:Container(
height: 800,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children:[
Text("R1",style: TextStyle(fontSize: 30),),
Text("R2",style: TextStyle(fontSize: 30),),
Text("R3",style: TextStyle(fontSize: 30),),
Text("R4",style: TextStyle(fontSize: 30),),
ElevatedButton(onPressed :(){
},child:Text("Button"))
]
),
)What is Cross Axis Alignment And Main Cross Axis Alignment
Columns
//Same type use
//IMP = many time you used to Columns and rows
body:Container(
width: 500,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children:[
Text("R1",style: TextStyle(fontSize: 30),),
Text("R2",style: TextStyle(fontSize: 30),),
Text("R3",style: TextStyle(fontSize: 30),),
Text("R4",style: TextStyle(fontSize: 30),),
ElevatedButton(onPressed :(){
},child:Text("Button"))
]
),
)Use different different time rows and columns
body:Container(
// width: 500,height:100,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Text("R1",style: TextStyle(fontSize: 30),),
Row(
mainAxisAlignment: MainAxisAlignment.end,
// crossAxisAlignment: CrossAxisAlignment.,
children: [OutlinedButton(onPressed: (){
},child: Text("click here"),)
],
),
Text("R2",style: TextStyle(fontSize: 30),),
Text("R3",style: TextStyle(fontSize: 30),),
Column(
mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.,
children: [OutlinedButton(onPressed: (){
},child: Text("click here"),)
],
), Row(
mainAxisAlignment: MainAxisAlignment.end,
// crossAxisAlignment: CrossAxisAlignment.,
children: [OutlinedButton(onPressed: (){
},child: Text("click here"),)
],
),
Text("R4",style: TextStyle(fontSize: 30),),
ElevatedButton(onPressed :(){
},child:Text("Button"))
]
),
)InkWell Widget ,Important In Flutter
body:InkWell(
onTap: (){
print("Tapped on container");
},
onLongPress: (){
print("Long Tapped on container");
},
onDoubleTap: (){
print("Double tapped on container");
},
child: Center(
child: Container(
width: 200,
height: 200,
color: Colors.amberAccent,
child:
InkWell(
onTap: (){
print("click on Text");
},
child: Center(child: Text("Click here",style: TextStyle
(fontSize: 30,
fontWeight:FontWeight.w800),
)
),
),
),
),
)Flutter ScrollView Type And It's Type
body: Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Container(
margin: EdgeInsets.only(right: 10),
width: 200,
height: 200,
color: Colors.blue,
),
Container(
margin: EdgeInsets.only(right: 10),
width: 200,
height: 200,
color: Colors.red,
),
Container(
margin: EdgeInsets.only(right: 10),
width: 200,
height: 200,
color: Colors.green,
),
Container(
margin: EdgeInsets.only(right: 10),
width: 200,
height: 200,
color: Colors.lightBlueAccent,
),
Container(
width: 200,
height: 200,
color: Colors.deepPurple,
),
],
),
),
),
Container(
margin: EdgeInsets.only(bottom: 10),
height: 200,
color: Colors.lightBlueAccent,
),
Container(
margin: EdgeInsets.only(bottom: 10),
height: 200,
color: Colors.redAccent,
),
Container(
margin: EdgeInsets.only(bottom: 10),
height: 200,
color: Colors.green,
),
Container(
margin: EdgeInsets.only(bottom: 10),
height: 200,
color: Colors.purple,
),
Container(
margin: EdgeInsets.only(bottom: 10),
height: 200,
color: Colors.blue,
),
],
),
),
List View Widget And it's Components
- Listview in flutter is a widget used to display items in a linear manner.
- For example, list view is used in apps like zomato & swiggy to display a list of restaurants.
- Since it is a scrollable widget we can display multiple items on the same screen.
- If the scroll direction is vertical the children will be arranged one after another from top to bottom.
- When the scroll direction is horizontal the children will be arranged from left to right.
Simply explain List View
body: ListView(
reverse: true,
scrollDirection: Axis.horizontal,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("one",style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("two",style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("three",style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("four",style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold),),
)
],
),//First a create an array and difine a value
//then
var arrName = [ "Ram","kamlesh","nitesh ","Rahul","ramesh","haresh","sachin"];//then
body: ListView.builder(itemBuilder: (context ,index ){
return Text(arrName[index],style: TextStyle(fontWeight: FontWeight.w500,fontSize: 30),);
},
itemCount: arrName.length,
itemExtent: 120,
scrollDirection: Axis.horizontal,
),List View separated
//create an array
var arrName = [ "Ram","kamlesh","nitesh ","Rahul","ramesh","haresh","sachin"];body: ListView.separated(itemBuilder: (context , index ) {
return Text(arrName[index] ,style: TextStyle(fontWeight: FontWeight.w600,fontSize: 30),);
},
itemCount: arrName.length,
separatorBuilder: (context , index){
return Divider(height: 100,thickness: 5,);
},
),
Example Of ListView With Rows And Columns
//create an array
var arrName = [ "Ram","kamlesh","nitesh ","Rahul","ramesh","haresh","sachin"];//then
body: ListView.separated(itemBuilder: (context , index ) {
return
Row(
children:[
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(arrName[index],style: TextStyle(fontSize: 31,fontWeight: FontWeight.bold),),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(arrName[index],style: TextStyle(fontSize: 21,fontWeight: FontWeight.bold),),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(arrName[index],style: TextStyle(fontSize: 31,fontWeight: FontWeight.bold),),
)
]
);
},
itemCount: arrName.length,
separatorBuilder: (context , index) {
return Divider(height: 100,thickness: 3,);
},
),import 'package:flutter/material.dart';
void main(){
runApp(MyFlutterApp()); //Create Function and class call
}
class MyFlutterApp extends StatelessWidget{ //extends with class
@override // Alt + enter , right click new .... create 1 override
Widget build(BuildContext context) {
return MaterialApp( //android for use material app
title: "Flutter App",
theme: ThemeData(
primarySwatch: Colors.deepPurple
),
home: AppHomePage(), //home page create with constrictor call
);
}
}
class AppHomePage extends StatelessWidget{ //create home page with class
@override
Widget build(BuildContext context) {
return Scaffold( // return scaffold
appBar: AppBar( //scaffold two value app bar and app body
title: Text("Home"),
// debugShowCheckedModeBanner:true, //remove debug show
),
body: Center( //main body all widget in it
child: Container(
width: 200,
height: 200,
color: Colors.lightBlue,
),
),
);
}
}




















Comments
Post a Comment