SHARE
TWEET

Untitled

a guest Oct 21st, 2019 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. printInteger(int number){
  2.   print('The no. is $number');
  3. }
  4.  
  5. bool isHot(a,hotModel){
  6.  
  7.   var i = 0;
  8.   var f = true;
  9.   while(i <= hotModel.length){
  10.     if(hotModel[i] != a)
  11.       f = false;
  12.     else
  13.       {
  14.         f = true;
  15.         break;
  16.       }
  17.  
  18.     i = i + 1;
  19.   }
  20.  
  21.   return f;
  22.  
  23. }
  24.  
  25.  
  26. main(){
  27.  
  28. /*
  29.     Variables
  30.     A variable in Dart stores references to a object.
  31.     e.g. var name = "Ameya";
  32.     here var named name is a reference to a String object and the values stored is "Ameya"
  33.  
  34.     Another way of writing the abovementioned line of code is by explicitly referring the variable name by its Object name as:
  35.     String name = "Ameya";
  36.  
  37.     Uninitialized variables have a default value of null;
  38.  
  39.     If an object is not specified to a fixed data type declare it as dynamic.
  40.     dynamic name = "Ameya";
  41.  */
  42.  
  43.  var number = 12;
  44.  
  45.  /* Data Types in Dart
  46.     1. numbers
  47.      int: -2^63 to 2^63-1 on dart vm.
  48.      double: 64bit double-precision floating point no., as specified by the IEEE 754 standard.
  49.  
  50.      methods like abs(), floor(), etc. from dart:math library can be used.
  51. */
  52.      //conversions--> String -> int
  53.  
  54. var one = int.parse('1');
  55. assert(one == 1);
  56. /*
  57.   Assert
  58.   Form: assert(condition, optionalMsg);
  59.   The 1rst arg in assert can be any expression which evaluates to a boolean value.
  60.   If the expression evals to a true value the assertion succeds and continues else it throws an exception.
  61.   Production code ignores assert, it is run in debug mode.
  62.  
  63.   If you never intend to change the value of a variable declare it as final or constant.
  64.  
  65.  */
  66.  
  67.  //String -> double
  68. var onePointOne = double.parse('1.1');
  69. assert(onePointOne == 1.1);
  70.  
  71.  //int -> String
  72. String oneAsString = 1.toString();
  73. assert(oneAsString == '1');
  74.  
  75. //double -> String
  76. String piAsString = 3.14159.toStringAsFixed(2);
  77. assert(piAsString == '3.14');
  78. /*
  79.      2. strings
  80.      A Dart string is a sequence of UTF-16 code units. Single/Double quotes are used to create a string.*/
  81.      //some special cases-->
  82.       print('Let\'s escape the string delimiter!!');
  83.     //multiline string.
  84.       print('''
  85.         Mary had a little lamb,
  86.         little lamb,
  87.         little lamb....
  88.       '''
  89.       );
  90.   /*
  91.      3. booleans
  92.     4. list 5. sets 6. maps 7. runes(for expressing unicode chars in strings)
  93.     5. symbols
  94.     Because every variable in Dart refers to an object, constructors can be used to initialize variables.
  95.  
  96.  * */
  97.  printInteger(number);
  98.  
  99.  //Spread operator
  100.   var a = ["apple","mango","banana"];
  101.   var b = ["strawberries", ...a];
  102.   print(b[0].split('a'));
  103.  
  104.     //Higher Order Array Methods:
  105.   b.forEach((item) => print("${b.indexOf(item) + 1} : $item"));
  106.  
  107.   //var mapped = b.map((item) => return item.t);
  108.  
  109.   print(mapped);
  110.   //Null Aware spread operator
  111.   var c;
  112.   var d = ["Happy","Sporer",...?c];
  113.   print(d.length);
  114.  
  115.   //collection if
  116.   //collection for:
  117.   c = [1,2,3];
  118.   d = ["0",for(var i in c) i.toString()];
  119.   print(d);
  120.   print(d.runtimeType);
  121.  
  122.   /*Set
  123.     A Set is an unordered collection of unique objects of the same data type
  124.  
  125.     An empty can be declared by:
  126.     var s = <int>{};
  127.     or by
  128.     Set<int> s = {};
  129.    */
  130.  
  131.   Set<String> friends = {"Ameya","Rachit","Z"};
  132.  
  133.   //add an element using a add() method, add a set to a set by the addAll() method.
  134.   //Like the List it supports the collection operators and spread operators.
  135.  
  136.   /*Map
  137.     A Map is an object that associates keys with values.
  138.     The key and values can be any type of Objects. 2 or more key's can hold the same value, but not vice-versa.
  139.    */
  140.   var hotModels = {
  141.     1 : 'Kylie Jenner',
  142.     2 : 'Kim Kardasian',
  143.     3 : 'Khloe Kardasian',
  144.     4 : 'Gigi Hadid',
  145.     5 : 'Kendall Jenner',
  146.     6 : 'Olivia Culpo'
  147.   };
  148.  
  149.   //Like the List it supports the collection operators and spread operators.
  150.   /* Functions
  151.       Functions are also objects. This means functions can be assigned to variables and functions can be passsed as parameters to other functions.
  152.  
  153.    */
  154.  
  155.   print(isHot("Olivia Culpo", hotModels));
  156.  
  157.   /*Functions can have required parameters and optional parameters
  158.       Optional Parameters are of 2 types: 1. Named and 2. Position
  159.  
  160.       1. Named parameters : e.g.
  161.       2. Positional parameters :
  162.    */
  163.  
  164.  
  165.  
  166.  
  167.  
  168. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top