skip to Main Content

I am trying to signup the user but getting this error

type 'TextEditingController' is not a subtype of type 'String'

Here is my code:

import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:shoppingmart/common_widget/app_logo_widget.dart';
import 'package:shoppingmart/common_widget/bg_widget.dart';
import 'package:shoppingmart/common_widget/custom_textfield.dart';
import 'package:shoppingmart/common_widget/our_button.dart';
import 'package:shoppingmart/const/consts.dart';
import 'package:shoppingmart/const/List.dart';
import 'package:shoppingmart/controller/auth_controller.dart';
import 'package:shoppingmart/screens/auth_screen/login_screen.dart';
import 'package:shoppingmart/screens/home/home.dart';
import 'package:status_alert/status_alert.dart';

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

  @override
  State<SignUp> createState() => _SignUpState();
}

class _SignUpState extends State<SignUp> {
  bool isCheck = false;
  var controller = Get.put(AuthController());

  //text controllers
  TextEditingController nameController = TextEditingController();
  TextEditingController emailController = TextEditingController();
  TextEditingController passwordController = TextEditingController();
  TextEditingController confirmPasswordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return bgWidget(
        child: Scaffold(
            resizeToAvoidBottomInset: false,
            body: Center(
              child: Column(
                children: [
                  (context.screenHeight * 0.1).heightBox,
                  applogoWidget(),
                  10.heightBox,
                  "Signup to $appname".text.white.fontFamily(bold).make(),
                  20.heightBox,
                  Column(
                    children: [
                      CustomTextField(
                          obsecuretext: false,
                          title: name,
                          hint: nameHint,
                          controller: nameController),
                      CustomTextField(
                          obsecuretext: false,
                          title: email,
                          hint: emailHint,
                          controller: emailController),
                      CustomTextField(
                          obsecuretext: true,
                          title: password,
                          hint: passwordHint,
                          controller: passwordController),
                      CustomTextField(
                          obsecuretext: true,
                          title: confirmPassword,
                          hint: passwordHint,
                          controller: confirmPasswordController),
                      Align(
                          alignment: Alignment.centerRight,
                          child: TextButton(
                              onPressed: () {},
                              child: forgetPass.text.size(15).make())),
                      5.heightBox,
                      Row(
                        children: [
                          Checkbox(
                            activeColor: redColor,
                            checkColor: whiteColor,
                            value: isCheck,
                            onChanged: (newValue) {
                              setState(() {
                                isCheck = newValue!;
                              });
                            },
                          ),
                          5.widthBox,
                          Expanded(
                            child: RichText(
                                text: const TextSpan(children: [
                              TextSpan(
                                  text: "I agree to the ",
                                  style: TextStyle(
                                      color: fontGrey, fontFamily: regular)),
                              TextSpan(
                                  text: termsandCondition,
                                  style: TextStyle(
                                      color: redColor, fontFamily: regular)),
                              TextSpan(
                                  text: " & ",
                                  style: TextStyle(
                                      color: fontGrey, fontFamily: regular)),
                              TextSpan(
                                  text: privacyPolicy,
                                  style: TextStyle(
                                      color: redColor, fontFamily: regular)),
                            ])),
                          ),
                        ],
                      ),
                      ourButton(
                          title: signup,
                          color: redColor,
                          textColor: whiteColor,
                          onPress: () async {
                            if (passwordController.text ==
                                confirmPasswordController.text) {
                              if (isCheck != false) {
                                try {
                                  await controller
                                      .signupMethod(
                                    context: context,
                                    email: emailController,
                                    password: passwordController,
                                  )
                                      .then((value) {
                                    return controller
                                        .storeUserData(
                                            name: nameController,
                                            email: emailController,
                                            password: passwordController)
                                        .then((value) {
                                      VxToast.show(context,
                                          msg: 'Account Created Sucessfully');
                                      Get.offAll(LoginScreen());
                                    });
                                  });
                                } catch (e) {
                                  VxToast.show(context, msg: e.toString());
                                  FirebaseAuth.instance.signOut();
                                }
                              }
                            } else {
                              VxToast.show(context,
                                  msg: 'Confirm password should be same');
                            }
                          }).box.width(context.screenWidth - 50).make(),
                      5.heightBox,
                      RichText(
                          text: const TextSpan(children: [
                        TextSpan(
                            text: alreadyhaveanAccount,
                            style: TextStyle(color: fontGrey)),
                        TextSpan(
                            text: login,
                            style:
                                TextStyle(color: redColor, fontFamily: bold)),
                      ])).onTap(() {
                        Get.back();
                      })
                    ],
                  )
                      .box
                      .white
                      .rounded
                      .padding(const EdgeInsets.all(16))
                      .width(context.screenWidth - 60)
                      .shadowSm
                      .make(),
                ],
              ),
            )));
  }
}

Error Log

I/flutter ( 5199): type 'TextEditingController' is not a subtype of type 'String'
D/FirebaseAuth( 5199): Notifying id token listeners about a sign-out event.
D/FirebaseAuth( 5199): Notifying auth state listeners about a sign-out event.
I/flutter ( 5199): Color(0xdd000000)

Appreciate your answer

3

Answers


  1. add .text next to your controllers

    example

    .storeUserData(
      name: nameController.text
    

    instead of

    .storeUserData(
          name: nameController
    

    and so with others controllers .

    Login or Signup to reply.
  2. import 'package:get/get.dart';
    import 'package:get/get_core/src/get_main.dart';
    import 'package:get/get_navigation/get_navigation.dart';
    import 'package:shoppingmart/common_widget/app_logo_widget.dart';
    import 'package:shoppingmart/common_widget/bg_widget.dart';
    import 'package:shoppingmart/common_widget/custom_textfield.dart';
    import 'package:shoppingmart/common_widget/our_button.dart';
    import 'package:shoppingmart/const/consts.dart';
    import 'package:shoppingmart/const/List.dart';
    import 'package:shoppingmart/controller/auth_controller.dart';
    import 'package:shoppingmart/screens/auth_screen/login_screen.dart';
    import 'package:shoppingmart/screens/home/home.dart';
    import 'package:status_alert/status_alert.dart';
    
    class SignUp extends StatefulWidget {
      const SignUp({super.key});
    
      @override
      State<SignUp> createState() => _SignUpState();
    }
    
    class _SignUpState extends State<SignUp> {
      bool isCheck = false;
      var controller = Get.put(AuthController());
    
      //text controllers
      TextEditingController nameController = TextEditingController();
      TextEditingController emailController = TextEditingController();
      TextEditingController passwordController = TextEditingController();
      TextEditingController confirmPasswordController = TextEditingController();
    
      @override
      Widget build(BuildContext context) {
        return bgWidget(
            child: Scaffold(
                resizeToAvoidBottomInset: false,
                body: Center(
                  child: Column(
                    children: [
                      (context.screenHeight * 0.1).heightBox,
                      applogoWidget(),
                      10.heightBox,
                      "Signup to $appname".text.white.fontFamily(bold).make(),
                      20.heightBox,
                      Column(
                        children: [
                          CustomTextField(
                              obsecuretext: false,
                              title: name,
                              hint: nameHint,
                              controller: nameController),
                          CustomTextField(
                              obsecuretext: false,
                              title: email,
                              hint: emailHint,
                              controller: emailController),
                          CustomTextField(
                              obsecuretext: true,
                              title: password,
                              hint: passwordHint,
                              controller: passwordController),
                          CustomTextField(
                              obsecuretext: true,
                              title: confirmPassword,
                              hint: passwordHint,
                              controller: confirmPasswordController),
                          Align(
                              alignment: Alignment.centerRight,
                              child: TextButton(
                                  onPressed: () {},
                                  child: forgetPass.text.size(15).make())),
                          5.heightBox,
                          Row(
                            children: [
                              Checkbox(
                                activeColor: redColor,
                                checkColor: whiteColor,
                                value: isCheck,
                                onChanged: (newValue) {
                                  setState(() {
                                    isCheck = newValue!;
                                  });
                                },
                              ),
                              5.widthBox,
                              Expanded(
                                child: RichText(
                                    text: const TextSpan(children: [
                                  TextSpan(
                                      text: "I agree to the ",
                                      style: TextStyle(
                                          color: fontGrey, fontFamily: regular)),
                                  TextSpan(
                                      text: termsandCondition,
                                      style: TextStyle(
                                          color: redColor, fontFamily: regular)),
                                  TextSpan(
                                      text: " & ",
                                      style: TextStyle(
                                          color: fontGrey, fontFamily: regular)),
                                  TextSpan(
                                      text: privacyPolicy,
                                      style: TextStyle(
                                          color: redColor, fontFamily: regular)),
                                ])),
                              ),
                            ],
                          ),
                          ourButton(
                              title: signup,
                              color: redColor,
                              textColor: whiteColor,
                              onPress: () async {
                                if (passwordController.text ==
                                    confirmPasswordController.text) {
                                  if (isCheck != false) {
                                    try {
                                      await controller
                                          .signupMethod(
                                        context: context,
                                        email: emailController,
                                        password: passwordController,
                                      )
                                          .then((value) {
                                        return controller
                                            .storeUserData(
                                                name: nameController.text,
                                                email: emailController.text,
                                                password: passwordController.text)
                                            .then((value) {
                                          VxToast.show(context,
                                              msg: 'Account Created Sucessfully');
                                          Get.offAll(LoginScreen());
                                        });
                                      });
                                    } catch (e) {
                                      VxToast.show(context, msg: e.toString());
                                      FirebaseAuth.instance.signOut();
                                    }
                                  }
                                } else {
                                  VxToast.show(context,
                                      msg: 'Confirm password should be same');
                                }
                              }).box.width(context.screenWidth - 50).make(),
                          5.heightBox,
                          RichText(
                              text: const TextSpan(children: [
                            TextSpan(
                                text: alreadyhaveanAccount,
                                style: TextStyle(color: fontGrey)),
                            TextSpan(
                                text: login,
                                style:
                                    TextStyle(color: redColor, fontFamily: bold)),
                          ])).onTap(() {
                            Get.back();
                          })
                        ],
                      )
                          .box
                          .white
                          .rounded
                          .padding(const EdgeInsets.all(16))
                          .width(context.screenWidth - 60)
                          .shadowSm
                          .make(),
                    ],
                  ),
                )));
      }
    }
    
    Login or Signup to reply.
  3. It looks like you are providing actual TextEditingController objects to your AuthController methods (signupMethod & storeUserData).

    It also seems like your AuthController methods (above) are expecting String values for those methods. You should rather provide the values like:

    await controller.signupMethod(
     context: context,
     email: emailController.text,
     password: passwordController.text,
    )
    

    and

    await controller.storeUserData(
     name: nameController.text,
     email: emailController.text,
     password: passwordController.text,
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search