In Dart, they recommend you to use get keyword for getters, like:
String get text => "Hi there"; // recommended
instead of
String getText() => "Hi there"; // not recommended
I was wondering how can I solve following case using get? And if there is no way of doing it then why Dart recommends things like get, when things can be done easily by getX() way?
// how to solve it using recommended way i.e. using "get"?
String getText(bool value) {
return value ? "Hi" : "There";
}
get keyword is used for standard getters - when you need just to return some field or value. It's like the such keyword in Kotlin.
But if you want to use some parameters - you can't use get in this case - you have to make function getX([some params])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With