-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d075187
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'dart:async'; | ||
|
||
void main() { | ||
int FromTime = 11; | ||
Timer.periodic(Duration(seconds: 1), (timer) { | ||
if (FromTime == 1) { | ||
timer.cancel(); | ||
} else { | ||
FromTime--; | ||
print(FromTime); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'dart:io'; | ||
|
||
void main() { | ||
try { | ||
stdout.write("Enter First number: "); | ||
int firstNum = int.parse(stdin.readLineSync().toString()); | ||
stdout.write("Enter Second number: "); | ||
int secondNum = int.parse(stdin.readLineSync().toString()); | ||
var cal = Calculator(); | ||
//Sum = return type | ||
var sum = cal.sum(a: firstNum, b: secondNum); | ||
print("Sum: " + sum.toString()); | ||
//Other operation = non return type | ||
cal.sub(a: firstNum, b: secondNum); | ||
cal.mult(a: firstNum, b: secondNum); | ||
cal.div(a: firstNum, b: secondNum); | ||
} on FormatException catch (number) { | ||
print("Invlaid number format in input field"); | ||
} catch (error) { | ||
print(error); | ||
} | ||
} | ||
|
||
class Calculator { | ||
late int num1; | ||
late int num2; | ||
|
||
int sum({a, b}) { | ||
this.num1 = a; | ||
this.num2 = b; | ||
return num1 + num2; | ||
} | ||
|
||
void sub({a, b}) { | ||
this.num1 = a; | ||
this.num2 = b; | ||
print("Substraction: ${num1 - num2}"); | ||
} | ||
|
||
void mult({a, b}) { | ||
this.num1 = a; | ||
this.num2 = b; | ||
print("Multiplication: ${num1 * num2}"); | ||
} | ||
|
||
void div({a, b}) { | ||
this.num1 = a; | ||
this.num2 = b; | ||
print("Division: ${num1 / num2}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:math'; | ||
|
||
void main() { | ||
// DateTime todaydt = DateTime.now(); | ||
// var milisec = todaydt.millisecond; | ||
|
||
// var randomFace = Dice(); | ||
// print("You get: "); | ||
// print('${randomFace.diceFace(a: milisec)}'); | ||
// } | ||
|
||
// class Dice { | ||
// late int a; | ||
// int diceFace({a}) { | ||
// return (a % 6 + 1); | ||
// } | ||
var list = [1,2,3]; | ||
var ran = Random(); | ||
print(list[ran.nextInt(list.length)]); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
void main() { | ||
/*String repeat = | ||
"lal kumar pun" * 5; //used on testing purpose for many dummy datas | ||
print(repeat); */ // This is string multiplications | ||
// store(); | ||
SpreadOperator(); | ||
} | ||
//--------------------Use of future keywords with async and await keywords----------------------------------- | ||
|
||
/* void store() async { | ||
//async and await used during using of future only | ||
var data = await downloads(); | ||
print(data); | ||
} | ||
Future<String> downloads() { | ||
var result = Future.delayed(Duration(seconds: 3), () { | ||
return "hello future code works dear lal for async and await"; | ||
}); | ||
return result; | ||
} */ | ||
|
||
/* -----------------------Use of future keywords with then keywords----------------------------------- | ||
// using then keyword have feautures of error in dart languages than that of await and async | ||
void store() { | ||
// Future<String> data = downloads(); neeeds in future | ||
var data = downloads(); // needs immediatley | ||
data.then((response) => print(response), onError: (Error) { | ||
print(Error); | ||
}); | ||
} | ||
Future<String> downloads() { | ||
Future<String> result = Future.delayed(Duration(seconds: 3), () { | ||
return Future.error("hello error for then keywords"); | ||
}); | ||
return result; | ||
}*/ | ||
|
||
//-------------------SPREAD OPERATOR------------------------------------------------------------------- | ||
|
||
void SpreadOperator() { | ||
var marks = 30; | ||
//-----------------IF ELSE shortcut | ||
// bool ifElseShorcut = true; | ||
// ifElseShorcut ? "its true condition" : "else false condition"; | ||
List<String> std = [ | ||
"lal", | ||
if (marks > 40) ...["not match"], | ||
if (marks > 20) ...["match"] | ||
]; | ||
print(std); | ||
} |