'Flutter The method 'User' isn't defined for the type '_LeaveApplicationState'

I am building an app using Flutter and Firebase for the backend. I was Following a tutorial guide but when I have written the code am getting two types of errors, the first one being; "The method 'User' isn't defined for the type '_LeaveApplicationState' "

class LeaveApplication extends StatefulWidget {
  const LeaveApplication({Key? key}) : super(key: key);

  @override
  _LeaveApplicationState createState() => _LeaveApplicationState();
}

class _LeaveApplicationState extends State<LeaveApplication> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final controllerFirstName = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.all(24),
          child: Form(
            key: _formKey,
            child: Column(
              children: <Widget>[
                const Text(
                  'Apply For Work Leave',
                  style: TextStyle(
                    fontWeight: FontWeight.w700,
                    fontSize: 18,
                    color: Colors.black,
                  ),
                ),
                //rest of code....

                  child: MaterialButton(
                    color: Colors.lightBlue,
                    onPressed: () {
                      final user = **User**(
                        fname: controllerFirstName.text,
                        lname: controllerLastName.text,
                        email: controllerEmail.text,
                        phoneno: int.parse(controllerPhoneNo.text),
                        leave: controllerLeaveType,
                        duration: controllerDuration.text,
                      );

                      Navigator.pop(context);

                      createUser(user);

                      if (_formKey.currentState!.validate()) {
                        ScaffoldMessenger.of(context).showSnackBar(
                          const SnackBar(content: Text('Request Sent')),
                        );
                      }
                    },
             
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Future createUser(**User** user) async {
    final docUser = FirebaseFirestore.instance.collection('employees').doc();
    user.id = docUser.id;

    final json = user.toJson();
    await docUser.set(json);
  }
}

the second error is "Undefined class 'User'." the errors arise in the areas which are in bold/asterisk. I want the user who has logged in to be able to put in details and send them to firebase datebase. Can anyone help



Solution 1:[1]

If you are importing your user model class this should work fine i will sujjest you to change the name of your user class to something else because firebase also have a user class might you had imported that one please recheck again and let me know if this works

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 Tarun