Home > database >  The named parameter 'userId' isn't defined
The named parameter 'userId' isn't defined

Time:05-07

am trying to call the user again while he is auth == true . when the user press he need to be called the same user . any solutions?

class upload extends StatefulWidget {
  String? userId;
  upload({Key? key, this.userId}) : super(key: key);

  @override
  State<upload> createState() => _uploadState();
}

class _uploadState extends State<upload> {
  File? file;
  String? downloadUrl;
//.......
//.......
//.......
 @override
  void initState() {
    super.initState();
    FirebaseFirestore.instance
        .collection("users")
        .doc(user!.uid)
        .get()
        .then((value) {
      this.loggedInUser = usermodel.fromMap(value.data());
      setState(() {});
    });
  }
//...........
//...........
onPressed: () => selectImage(context, userId: loggedInUser.uid),
~~~!

CodePudding user response:

In your selectImage function, if you defined it like this:

selectImage(BuildContext context, String userId) {
//....etc

then when you call the method, it should look like this:

onPressed: () => selectImage(context, loggedInUser.uid),

Because you are using positional parameters, not named parameters.

If you want to use named, change it to this:

selectImage({required BuildContext context, required String userId}) {
//....etc
onPressed: () => selectImage(context: context, userId: loggedInUser.uid),

  • Related