Posts

Showing posts from May, 2021
DART   MIXINS Mixins are a way of reusing a class’s code in multiple class hierarchies.  
  DART   Static // to make any variable universal for all object belongs to that class // static is also applied to method of class // static work without any constructor int main(){ // Square myShape = Square(); not need constructor static int side = Square. noOfSide ; print(side) ; // Circle().getOurCircumference(radius: 20); // without static Circle. getOurCircumference (radius: 20 ) ; // with static, call by this // static work without any constructor as we seen above } class Square{ static int noOfSide = 4 ; } class Circle{ static const double pi = 3.1415926 ; static void getOurCircumference ({double radius}){ double circumference = 2 * pi * radius ; print(circumference) ; } }
  Building Platform Specific UI (android and iOS)                 lect(14 -6)        First import dart: io create method in class for both platform and apply using(creating) a new method or using ternary operator  Then  Platform. isIOS and  Platform. isAndroid
Image
[ Dart ]  Loops Type-1 void main () { buyMilk( 7 ) ; } void buyMilk (int days) { for (int i = 1 ; i <= days ; i++) { print( 'Buying milk on day $i ' ) ; } } Type-2   Example List<String> fruits = [ 'Apple' , 'Mango' , 'Banana' , 'Strawberry' , 'Grapes' ] ; void main(){ pieMaker() ; } void pieMaker (){ for (String fruit in fruits){ print(fruit + ' Pie' ) ; } } Example List<int> winningNumbers = [ 12 , 6 , 34 , 22 , 41 , 9 ] ; void main(){ List<int> ticket1 = [ 45 , 2 , 9 , 18 , 12 , 33 ] ; List<int> ticket2 = [ 41 , 17 , 26 , 7 , 35 , 32 ] ; checkNumber(ticket1) ; } void checkNumber (List<int> myNumber){ int match = 0 ; for (int myNum in myNumber){ for (int winNum in winningNumbers){ if (myNum == winNum){ match++ ; } } } print( 'Got a $match matches' ) ; }
DropDownButton
API  FETCHING DATA FROM INTERNET  PASSING DATA TO A STATE OBJECT
Image
  DART EXCEPTION HANDLING PARSING    Change string value to double void main (){ String myString = 'abc' ; double myStringAsdouble = double. parse (myString) ; print(myStringAsdouble + 56 ) ; }      Used example in a program how to use try and catch   Catch takes the error and print in flutter terminal as written in code   @override Widget build (BuildContext context) { String myString = "abc" ; double margin ; try { margin = double. parse (myString) ; } catch (e) { print(e) ; margin = 30 ; // use this or } return Scaffold ( body: Container ( margin: EdgeInsets . all (margin ?? 30 ) , // or use this color: Colors. grey , ) , ) ; } when margin takes value as 'abc' but it cant be converted into double so app return error message like below so we also give new margin value so that instead of that ('abc'), new value is used in a container  DART NULL AWARE OPERATOR As above we use margin ??...
 DART   ASYNC AWAIT FUTURE