css 颤动_颤动不同类型的功能

css 颤动

A quick low down on the different types Dart functions you might come across.

快速了解您可能遇到的不同类型的Dart功能。

功能类型: (Types of functions:)

  1. void functions e.g

    无效函数,例如
void greeting() { 
print(‘hello’);
}

2. functions with a return type e.g

2.具有返回类型的函数,例如

String greeting() { 
return ‘Hello’;
}

3. functions that take parameters

3.带有参数的函数

i. mandatory parameters e.g

强制参数,例如

void greeting(@required String greeting){ 
print(greeting);
}

ii. optional parameters

ii 。 可选参数

  • optional positional parameter e.g

    可选的位置参数,例如

void details([int telephone]) {...}
  • optional named parametere.g

    可选的命名参数,例如

void details({String firstName, String lastName}) {...}
  • optional parameter with default valuese.g

    具有默认值的可选参数,例如

void details({int age: 30}) {...}
  • a function with all possible types of parameters:

    具有所有可能类型的参数的函数:
void details (int id, [int telephone],{String firstName, String lastName}, {int age: 30}) {...}

and you could call it with:

您可以通过以下方式调用它:

details(1001)details(1001, 078787878787, firstName: John, lastName: Ham, age: 50)

4. Getters and Setters

4.获取器和设置器

Special methods that provide read and write access to an object’s properties.

提供对对象属性的读写访问权限的特殊方法。

class Car {
String make;
Car({this.make});String get make => make;void set make(String name) => make = name;}

to call:

致电:

Car myCar = Car(‘Porsche’);print(myCar.make);

不同的函数声明: (Different Function declarations:)

  1. Regular function e.g

    常规功能,例如
void greeting { 
print(‘hello’);
}

2. Lambda function/arrow function is a short form of a regular function that can only return one expression. (Arrows instead of curly brackets). e.g

2. Lambda函数/箭头函数是正则函数的缩写,只能返回一个表达式。 (用箭头代替大括号)。 例如

void greeting => print(‘hello’);

翻译自: https://medium.com/the-innovation/flutter-different-types-of-functions-e92461371660

css 颤动