Flutter : Class et cascading ..

Les CLASSES sous Flutter en DART : https://www.tutorialspoint.com/dart_programming/dart_programming_classes.htm

Le cascading permet de simplifier le code.

L’exemple ci-dessous est parlant :

  import 'dart:convert';

//An Example class with member attributes and methods
class Example{
  var a;
  var b;
  void bSetter(b)
  {
    this.b = b;
  }
  void printValues(){
    print(this.a);
    print(this.b);
  }
}

void main() {
    //Instantiating two Example objects
    Example eg1 = new Example();
    Example eg2 = new Example();

    //Using the .. operator for operations on Example object
    print("Example 1 results:");
    eg1
    ..a = 88
    ..bSetter(53)
    ..printValues();

    //The same operations as above but without the .. operator
    print("Example 2 results:");
    eg2.a = 88;
    eg2.bSetter(53);
    eg2.printValues();
}

Références :

https://stackoverflow.com/questions/17025769/how-do-method-cascades-work-exactly-in-dart

https://www.educative.io/edpresso/what-is-dart-cascade-notation

Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories
%d blogueurs aiment cette page :