Skip to content

Commit

Permalink
made some changes to the signup form
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish Sharma committed Feb 20, 2024
1 parent 089cb70 commit 554f45a
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions lib/signup_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:cloud_functions/cloud_functions.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -34,6 +36,7 @@ class SignUpPageState extends State<SignUpPage> {
TextEditingController();
final _formKey = GlobalKey<FormState>();
bool sendOtpSuccess = false;
bool isOtpButtonEnabled = true;

@override
void initState() {
Expand Down Expand Up @@ -144,9 +147,8 @@ class SignUpPageState extends State<SignUpPage> {
),
SignupForm(
stepNumber: "1",
fieldLabel: "Setup Kilvish Id",
buttonLabel: "Get Started",
hint: "crime-master-gogo",
fieldLabel: "Kilvish Id",
hint: "First time user ? Create a new kilvish id",
isActive: _stepNumber == 1 && (!sendOtpSuccess),
isOperationAllowedButNotActive: _stepNumber > 1,
buttonClickHandler: () => allowFormSubmission(1),
Expand All @@ -155,10 +157,7 @@ class SignUpPageState extends State<SignUpPage> {
),
SignupForm(
stepNumber: "2",
fieldLabel:
(_stepNumber == 2) ? "Phone Number" : "Update Phone Number",
buttonLabel:
(_stepNumber == 2) ? "Get OTP" : "Get OTP for new number",
fieldLabel: "Phone Number",
hint: "7019316063",
isActive: _stepNumber == 2 && (!sendOtpSuccess),
isOperationAllowedButNotActive: _stepNumber > 2,
Expand All @@ -169,14 +168,26 @@ class SignUpPageState extends State<SignUpPage> {
),
SignupForm(
stepNumber: "3",
fieldLabel: "Enter Email Id",
buttonLabel: "Send OTP",
fieldLabel: "Email Id",
buttonLabel: sendOtpSuccess
? (isOtpButtonEnabled ? "Re-requet OTP" : "Please wait ..")
: "Get OTP",
hint: "[email protected]",
isActive: _stepNumber == 3 && (!sendOtpSuccess),
isOperationAllowedButNotActive: _stepNumber > 3,
buttonClickHandler: () {
verifyUser();
setState(() {
_stepNumber = 4;
isOtpButtonEnabled = false;
});
Timer(const Duration(seconds: 10), () {
setState(() {
isOtpButtonEnabled = true;
});
});
},
buttonEnabled: isOtpButtonEnabled,
buttonVisible: true,
textFocus: _emailTextFocus,
controller: _emailTextEditingController,
Expand All @@ -193,8 +204,8 @@ class SignUpPageState extends State<SignUpPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
renderInputLabel("Phone OTP", _stepNumber == 4),
renderTextField(_otpPhoneTextEditingController,
"Enter Phone OTP", _otpPhoneTextFocus)
renderTextField(_otpPhoneTextEditingController, "xxxx",
_otpPhoneTextFocus)
],
)),
const SizedBox(width: 16),
Expand All @@ -204,8 +215,8 @@ class SignUpPageState extends State<SignUpPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
renderInputLabel("Email OTP", _stepNumber == 5),
renderTextField(_otpEmailTextEditingController,
"Enter Email OTP", _otpEmailTextFocus)
renderTextField(_otpEmailTextEditingController, "xxxx",
_otpEmailTextFocus)
],
)),
],
Expand Down Expand Up @@ -348,7 +359,7 @@ String? genericFieldValidator(String? value) {
class SignupForm extends StatefulWidget {
final String stepNumber;
final String fieldLabel;
final String buttonLabel;
final String? buttonLabel;
final String hint;
final bool isActive;
final bool isOperationAllowedButNotActive;
Expand All @@ -358,11 +369,12 @@ class SignupForm extends StatefulWidget {
final TextEditingController controller;
final TextInputAction textInputAction;
final bool buttonVisible;
final bool buttonEnabled;

const SignupForm({
required this.stepNumber,
required this.fieldLabel,
required this.buttonLabel,
this.buttonLabel,
required this.hint,
required this.isActive,
required this.isOperationAllowedButNotActive,
Expand All @@ -372,6 +384,7 @@ class SignupForm extends StatefulWidget {
required this.controller,
this.textInputAction = TextInputAction.next,
this.buttonVisible = false,
this.buttonEnabled = false,
super.key,
}) : fieldValidator = fieldvalidator ?? genericFieldValidator;

Expand Down Expand Up @@ -407,13 +420,7 @@ class SignupFormState extends State<SignupForm> {
],
),
]);
if (widget.isActive) {
//this will give focus to the active input field
widget.textFocus.requestFocus();
} else {
//this will give un focus to the in active input field
widget.textFocus.unfocus();
}

return uiWidget;
}

Expand Down Expand Up @@ -445,7 +452,6 @@ class SignupFormState extends State<SignupForm> {

Widget renderTextField() {
return TextFormField(
readOnly: !widget.isActive,
controller: widget.controller,
decoration: InputDecoration(
hintText: widget.isActive ? widget.hint : "",
Expand All @@ -456,27 +462,21 @@ class SignupFormState extends State<SignupForm> {
}

Widget renderFormSubmitButton() {
StadiumBorder? greyBorderIfNeeded = (widget.isOperationAllowedButNotActive)
StadiumBorder? greyBorderIfNeeded = (widget.buttonEnabled)
? const StadiumBorder(
side: BorderSide(color: primaryColor, width: 2),
)
: const StadiumBorder();
Color backgroundColor = (widget.isActive) ? primaryColor : inactiveColor;
Color backgroundColor =
(widget.buttonEnabled) ? primaryColor : inactiveColor;

return TextButton(
style: TextButton.styleFrom(
backgroundColor: backgroundColor,
minimumSize: const Size.fromHeight(50),
shape: greyBorderIfNeeded),
onPressed: widget.isActive
? () {
if (!widget.isActive && !widget.isOperationAllowedButNotActive) {
return denyFormSubmission();
}
widget.buttonClickHandler();
}
: null,
child: Text(widget.buttonLabel,
onPressed: widget.buttonEnabled ? widget.buttonClickHandler : null,
child: Text(widget.buttonLabel ?? "Click Me",
style: const TextStyle(color: Colors.white, fontSize: 15)),
);
}
Expand Down

0 comments on commit 554f45a

Please sign in to comment.