• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: flutter – how to pass required parameters when they have not yet been initialized

Resolved: flutter – how to pass required parameters when they have not yet been initialized

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am creating a userModel instance inside my authController and want to add obs from Getx to that userModel like: Rx<model.User>? userModel = model.User().obs;, but the fields inside my model.User are all required.
How can I pass these parameters if they have not yet been initialized as they will get initialized after the user signs in?
I referred this github: Github where he has done it because his parameters are not “required” as it is old, but now flutter is null safe and is forcing “required” parameters in my user model.
required error
AuthController code:
User model code:

Answer:

Add ? operator to tell explicity that the object can be null.
So the code goes like:

If you have better answer, please add a comment about this, thank you!

dart firebase flutter flutter-dependencies flutter-getx
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Resolved: mysql calculating to get profit or loss from 2 tables ( Purchases and Sales) in FIFO mode

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.