flutterfirebasedartpassword-recovery

Error: The argument type 'Future<dynamic>' can't be assigned to the parameter type 'void Function()?'


While making the Password Reset page, using Firebase Auth. I have made a few pages using Firebase but never encountered this kind of error, please suggest a solution.
It shows an error:-

Error: The argument type 'Future<dynamic>' can't be assigned to the parameter type 'void Function()?'.
lib/pages/forgot_pw_page.dart:82
 - 'Future' is from 'dart:async'.
                  onPressed: passwordReset(),

What I am doing wrong?

Code:

(I have trimmed the code, as it was not allowing to post whole)

class ForgotPasswordPage extends StatefulWidget {
  const ForgotPasswordPage({super.key});

  @override
  State<ForgotPasswordPage> createState() => _ForgotPasswordPageState();
}

class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
  final _emailController = TextEditingController();

  @override
  void dispose() {
    _emailController.dispose();
    super.dispose();
  }

  Future passwordReset() async {
    await FirebaseAuth.instance.sendPasswordResetEmail(email: _emailController.text.trim());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[300],
      body: SafeArea(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 25),
                child: MaterialButton(
                  onPressed: passwordReset(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Solution

  •   Future<void> passwordReset() async {}
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: MaterialButton(
            // onPressed: () => passwordReset(),
            onPressed: passwordReset,  
          ),
        );
      }