0

I have this 3 screen registration forms, the first one requests for Email, Password and Confirm password then the second screen requests for other users information including names, Phone number and address while the last one is the OTP confirmation page

Now I want to call all entered data into the first screen onto the second screen where I will confirm if the otp is correct before saving the data to database.

This is the registration model:

class Registration {
  int id;
  String firstNmae;
  String lastName;
  String email;
  String password;
  int phone;
  String address;

  Registration({
    this.id,
    this.firstNmae,
    this.lastName,
    this.email,
    this.password,
    this.phone,
    this.address,
  });
}

And this is my controller:

import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:signuptest/models/RegistrationModel.dart';

class RegistrationController extends GetxController {
  var registration = [];
}

On the first Signup Screen:

class SignUpForm extends StatefulWidget {
  @override
  _SignUpFormState createState() => _SignUpFormState();
}

class _SignUpFormState extends State<SignUpForm> {
  final RegistrationController registrationController =
      Get.find<RegistrationController>();

TextEditingController emailTextEditingController = TextEditingController();
  TextEditingController passwordTextEditingController = TextEditingController();
  TextEditingController cPasswordTextEditingController =
      TextEditingController();

...


//First Screen Onpressed Function:

      onpress: () {
                      if (_formKey.currentState.validate()) {
                        registrationController.registration.add(Registration(
                          email: emailTextEditingController.text,
                          password: passwordTextEditingController.text,
                        ));
                        Navigator.pushNamed(context, CompleteProfileScreen.routeName);
        }

Now on the complete Profile screen "Second Screen" i tried to display the data "Email Address" filled on the first screen to be sure it actually saving the user input but when typing the the name "email or emailTextEditingController" My VScode doesn't suggest the name for me and when I type it directly it shows red line under it

I tried passing the "email" as the value for the Text() widget:

class CompleteProfileForm extends StatefulWidget {
  @override
  _CompleteProfileFormState createState() => _CompleteProfileFormState();
}

class _CompleteProfileFormState extends State<CompleteProfileForm> {


  final RegistrationController registrationController =
      Get.put(RegistrationController());


...

 @override
  Widget build(BuildContext context) {
    return Form(
      child: Column(
        children: [
         Text(registrationController.registration.email), //I get a red line under the email which says..
...

The error I get is:

The getter 'email' isn't defined for the type 'List'. Try importing the library that defines 'email', correcting the name to the name of an existing getter, or defining a getter or field named 'email'

I guess I am calling it wrongly or something.

I have seen a lot of questions about same issues but most of them have no confirmed answer and secondly I don't want to pass the data as argument

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Britchi3
  • 180
  • 5
  • 17

1 Answers1

1

you are declaring the object wrong in the controller. It should be like this:

Registration registration;

and then on the first signup page:

registrationController.registration.email = emailTextEditingController.text;
registrationController.registration.password = passwordTextEditingController.text;

Your error was that you were declaring an empty array not the object of that class.

Asim Jawad
  • 163
  • 1
  • 10
  • When i added the code you provider on the First Signup page i got this error: ```Methods must have an explicit list of parameters. Try adding a parameter list.dart(missing_method_parameters) The name of a constructor must match the name of the enclosing class.``` – Britchi3 Jul 30 '21 at 15:49
  • But when i replaced the controller code, the registrationController.registration.email stopped displaying the error but i got a new one on the add funtion ```registrationController.registration.add(Registration( email: emailTextEditingController.text, password: passwordTextEditingController.text, ));``` this is the error i got ```The method 'add' isn't defined for the type 'Registration'.``` – Britchi3 Jul 30 '21 at 16:04
  • it is saying that .add is not a function clearly – Asim Jawad Jul 30 '21 at 16:43
  • have you added `Registration registration` to the controller? – Asim Jawad Jul 30 '21 at 16:44
  • yes, I have done that... so how do i fix the issue with the .add? – Britchi3 Jul 30 '21 at 16:54
  • you can not use .add with this – Asim Jawad Jul 30 '21 at 17:05
  • `registration.email = emailTextEditingController.text` should work fine – Asim Jawad Jul 30 '21 at 17:07