Is it possible, in Dart, to have generic methods in non-generic class, like in Java?
I use Getx for state management, DI & routing, but this question is not specific to Getx or Flutter.
I've AuthService
which deals with authentication and sets logged in user, like Rxn<AppUser>
. I've 3 types users: Customer extends AppUser
, Seller extends AppUser
& Admin extends AppUser
.
I want to change the user observable to something like this: Rxn<? extends AppUser> currentUser = Rxn()
.
I tried below syntax, but doesn't work.
class AuthService extends GetxService {
T Rxn<T extends AppUser> currentUser = Rxn();
...
}
Direct answer to my question:
Dart supports inheritance in generic types too (unlike in Java). So, Rxn<AppUser> currentUser = Rxn<Patient>()
is possible in Dart. I don't need wildcard or any.