Home > Software design >  The argument type 'string?' can't be assigned to the parameter type 'String"
The argument type 'string?' can't be assigned to the parameter type 'String"

Time:02-23

What are the errors about this code? Please can you make it correct and send me the code?

4 positional argument(s) expected, but 2 found. Try adding the missing arguments.

Undefined name '_formKey'. Try correcting the name to one that is defined, or defining the name.

Undefined name '_authData'. Try correcting the name to one that is defined, or defining the name.

Undefined name '_passwordController'. Try correcting the name to one that is defined, or defining the name.

Undefined name '_passwordController'. Try correcting the name to one that is defined, or defining the name.

The function '_submit' isn't defined. Try importing the library that defines '_submit', correcting the name to the name of an existing function, or defining a function named '_submit'.

Expected a method, getter, setter or operator declaration. This appears to be incomplete code. Try removing it or completing it.

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/authentication.dart';

import 'home_screen.dart';
import 'login_screen.dart';

class SignupScreen extends StatefulWidget {
static const routeName = '/signup';
@override
_SignupScreenState createState() => _SignupScreenState();
}

class _SignupScreenState extends State<SignupScreen> {

final GlobalKey<FormState> _formKey = GlobalKey();
TextEditingController _passwordController = new TextEditingController();

Map<String, String> _authData = {
'email' : '',
'password' : ''
};

void _showErrorDialog(String msg)
{
showDialog(
    context: context,
    builder: (ctx) => AlertDialog(
      title: Text('An Error Occured'),
      content: Text(msg),
      actions: <Widget>[
        FlatButton(
          child: Text('Okay'),
          onPressed: (){
            Navigator.of(ctx).pop();
          },
        )
      ],
    )
   );
  }

  Future<void> _submit() async
 {
  if(!_formKey.currentState!.validate())
  {
    return;
  }
 _formKey.currentState!.save();

 try{
  var key = 'email';
  await Provider.of<Authentication>(context, listen: false).signUp(
      _authData[key],
      _authData['password']
  );
  Navigator.of(context).pushReplacementNamed(HomeScreen.routeName);

  } catch(error)
 {
  var errorMessage = 'Authentication Failed. Please try again later.';
  _showErrorDialog(errorMessage);
 }
}
}
 @override
 Widget build(BuildContext context) {
 return Scaffold(
  appBar: AppBar(
    title: Text('Signup'),

    actions: <Widget>[
      FlatButton(
        child: Row(
          children: <Widget>[
            Text('Login'),
            Icon(Icons.person)
          ],
        ),
        textColor: Colors.white,
        onPressed: (){
          Navigator.of(context).pushReplacementNamed(LoginScreen.routeName);
        },
      )
    ],
  ),
  body: Stack(
    children: <Widget>[
      Container(
        decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [
                  Colors.limeAccent,
                  Colors.redAccent,
                ]
            )
        ),
      ),
      Center(
        child: Card(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Container(
            height: 300,
            width: 300,
            padding: EdgeInsets.all(16),
            child: Form(
              key: _formKey,
              child: SingleChildScrollView(
                child: Column(
                  children: <Widget>[
                    //email
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Email'),
                      keyboardType: TextInputType.emailAddress,
                      validator: (value)
                      {
                        if(value!.isEmpty || !value.contains('@'))
                        {
                          return 'invalid email';
                        }
                        return null;
                      },
                      onSaved: (value)
                      {
                        _authData['email'] = value!;
                      },
                    ),

                    //password
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Password'),
                      obscureText: true,
                      controller: _passwordController,
                      validator: (value)
                      {
                        if(value!.isEmpty || value.length<=5)
                        {
                          return 'invalid password';
                        }
                        return null;
                      },
                      onSaved: (value)
                      {
                        _authData['password'] = value!;
                      },
                    ),

                    //Confirm Password
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Confirm Password'),
                      obscureText: true,
                      validator: (value)
                      {
                        if(value!.isEmpty || value != _passwordController.text)
                        {
                          return 'invalid password';
                        }
                        return null;
                      },
                      onSaved: (value)
                      {

                      },
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    RaisedButton(
                      child: Text(
                          'Submit'
                      ),
                      onPressed: ()
                      {
                        _submit();
                      },
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(30),
                      ),
                      color: Colors.blue,
                      textColor: Colors.white,
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
       )
     ],
   ),
  );
 }
}

error image

  • Related