Skip to content

Commit

Permalink
dartLearning
Browse files Browse the repository at this point in the history
  • Loading branch information
atish-pun committed Jun 14, 2021
0 parents commit d075187
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Timer.dart
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);
}
});
}
51 changes: 51 additions & 0 deletions calculator.dart
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}");
}
}
22 changes: 22 additions & 0 deletions dice.dart
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)]);

}

54 changes: 54 additions & 0 deletions tips_tricks.dart
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);
}

0 comments on commit d075187

Please sign in to comment.