The named parameter 'onPressed' isn't defined

The name parameter 'on Pressed' isn't defined

I am trying to make an app with a sign in page but i can't make the button work


import 'package:flutter/material.dart';

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


  @override
  State<SignIn> createState() => _SignInState();
}

class _SignInState extends State<SignIn> {


  // ignore: unused_field
  final AuthService _auth = AuthService();

  // text field state
  String email = '';
  String password = '';



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.brown[100],
      appBar: AppBar(
        backgroundColor: Colors.brown[400],
        elevation: 0.0,
        title: const Text('Sign in to LejweConnect'),

      ),
      body: Container(
        padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
        child: Form(
          child: Column(
            children: <Widget>[
              const SizedBox(height: 20.0),
              TextFormField(
                onChanged: (val){
                  setState(() => email = val);

                }
              ),
              const SizedBox(height: 20.0),
                TextFormField(
                  obscureText: true,
                  onChanged: (val){
                    setState(() => password = val);

                  }
                ),
                const SizedBox(height: 20.0),
                Container(
                  color: Colors.pink[400],
                  // ignore: prefer_const_constructors
                  child: Text(
                   'Sign in',
                  style: const  TextStyle(color: Colors.white),
                  ),
                  
                  onPressed: () async {
                    
                  }

The named parameter 'onPressed' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'onPressed'.dartundefined_named_parameter

How do i fix this problem

Upvotes: -1

Views: 89

Answers (2)

Naman
Naman

Reputation: 1

You can not use onpressed inside of a container. Wrap your Container with GestureDectector and use onTap.

Upvotes: 0

innocent
innocent

Reputation: 965

You are passing onPressed to a container which doesn't accept onPressed as a parameter that's why you are getting onPressed error.

Only certain widgets accept onPressed parameters like buttons which you can use to do the press behaviour. Equivalently if you want to make the container clickable you can wrap it with InkWell and pass a the function to onTap. Eg:

InkWell(
  onTap: () {}, // paste your onPressed fn here
  child: Container(
    child: Text("test"),
  ),
)

Upvotes: 0

Related Questions