简体   繁体   中英

set/get keywords in Flutter/Dart

I am new at dart language and as a person who knows Java i did not understand get/set keywords in dart.What does get/set keywords does can you explain.

This is a function that makes using getter and setter more convenient.

String _name = "test";

get

//the same expression
String get name => _name;

String getName(){
  return _name;
}

set

//the same expression
set name(String name) => _name = name;

void setName(String name){
   _name = name;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM