'Rx<User>() missing argument - Flutter / GetX

While using a GetxController on a class, and using Rx to get a FirebaseUser, I'm being shown an error, that I'm missing a positional argument

class AuthController extends GetxController {
  FirebaseAuth _auth = FirebaseAuth.instance;
  Rx<User> _firebaseUser = Rx<User>();
  User get user => _firebaseUser.value;

Here on this Rx<User>() which is from package:firebase_auth/firebase_auth.dart, I get the error :

1 positional argument(s) expected, but 0 found. Try adding the missing arguments.dartnot_enough_positional_arguments

After launching the emulator, I get this more detailed error :

lib/core/controllers/auth_controller.dart:9:36: Error: Too few positional arguments: 1 required, 0 given. Rx _firebaseUser = Rx();

../../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.1.3/lib/get_rx/src/rx_types/rx_core/rx_impl.dart:324:3: Context: Found this candidate, but the arguments don't match. Rx(T initial) : super(initial);

I can't find what I'm supposed to add here, and every tutorial I saw, didn't specify any argument here. Anyone knows the problem ?



Solution 1:[1]

If you run with null safety, try it

 Rxn<User> firebaseUser = Rxn<User>();

https://pub.dev/documentation/get/latest/get_rx/get_rx-library.html

Solution 2:[2]

This may have something to do with how you're creating a custom observable object. If you check out the GetX docs, this is the suggested way to do what you're doing. Search for "model" on that page.

class AuthController extends GetxController {
  FirebaseAuth _auth = FirebaseAuth.instance;
  final firebaseUser = User().obs;
}

Also be aware that using getters and setter here is of no value. See this link for an explanation as to why

If that doesn't fix it, then try sharing your User class, and the rest of the Getx class, and how you're trying to access the firebaseUser from outside.

Solution 3:[3]

i was facing this issue but i changed getx package to 3.26.0 solved the issue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ersan Kolay
Solution 2 Loren.A
Solution 3 Ameer Safdar