Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter how to pass arguments to "get" method?

Tags:

flutter

dart

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";
}

1 Answers

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])

like image 194
Andrey Turkovsky Avatar answered Mar 09 '26 17:03

Andrey Turkovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!